enum fwp_endpoint_type_t {
- FWP_SEND_EPOIN = 0,
+ FWP_SEND_EPOINT = 0,
FWP_RECV_EPOINT = 1,
};
return 0;
}
-void fwp_endpoint_table_init()
-{
+void fwp_endpoint_table_init(){
int id;
for (id = 0; id < FWP_EPOINT_MAX; id++)
fwp_endpoint_table[id].status = FWP_EPOINT_CLOSED;
}
-struct fwp_endpoint* fwp_endpoint_create(int type, int node, int port)
-/* queueing policy should be the next parameter*/
+static struct fwp_endpoint* fwp_endpoint_alloc()
{
- int id,rc;
+ int id;
struct fwp_endpoint *epoint;
- /* Check for validity of the contract */
-#warning Wrong comments
- /* obtain fwp_vres_table mutex */
- pthread_mutex_lock(&fwp_epoint_table_lock);
+ pthread_mutex_lock(&fwp_endpoint_table_lock);
- /* find free vres id */
+ /* find free endpoint */
id = 0;
while ((id < FWP_EPOINT_MAX) &&
(fwp_endpoint_table[id].status != FWP_EPOINT_CLOSED)){
id++;
}
if (id == FWP_EPOINT_MAX) {
- /* release fwp_vres_table mutex */
- return -ENOMEM;
+ pthread_mutex_unlock(&fwp_endpoint_table_lock);
+ return NULL;
}
epoint = &fwp_endpoint_table[id];
epoint->status = FWP_EPOINT_OPENED;
- /* release fwp_vres_table mutex */
+
pthread_mutex_unlock(&fwp_endpoint_table_lock);
+
+ return epoint;
+}
+
+/**
+ * Creates endpoint
+ *
+ * \param type Specifies type of endpoint to create. The value FWP_SEND_EPOINT
+ * stands for send endpoint. The value FWP_RECV_EPOINT stands for receive
+ * endpoint.
+ *
+ * \param node IP address of destination node in case of send endpoint; local
+ * IP
+ */
+
+int fwp_send_endpoint_create(int node, int port, struct fwp_endpoint *epoint)
+{
+ if (!(epoint = fwp_endpoint_alloc())) {
+ return -ENOMEM;
+ }
+
epoint->addr.sin_family = AF_INET;
+ epoint->addr.sin_addr.s_addr = node;
epoint->addr.sin_port = htons(port);
- if (type == FWP_SEND_EPOINT) {
- epoint->addr.sin_addr.s_addr = node;
- return epoint;
- }
+ epoint->type = FWP_SEND_EPOINT;
- epoint->addr.sin_addr.s_addr = INADDR_ANY;
+ return 0;
+}
+
+int fwp_receive_endpoint_create(int port, struct fwp_endpoint *epoint)
+{
+ int rv;
- if ((epoint->sockd = socket(AF_INET, SOCK_DGRAM, 0)) == -1){
- perror("fwp_endpoint_create - socket error");
- return (-errno);
+ if (!(epoint = fwp_endpoint_alloc())) {
+ return -ENOMEM;
}
-
- if (bind(epoint->sockd, (struct sockaddr*) &epoint->addr,
- sizeof(epoint->addr)) == -1) {
-
- perror("fwp_endpoint_create - bind error");
- return (-errno);
+
+ epoint->type = FWP_RECV_EPOINT;
+ rv = fwp_create_inet_socket(port, &epoint->addr);
+ if (rv) {
+ epoint->sockd = rv;
+ return 0;
+ }
+ else {
+ fwp_endpoint_destroy(epoint);
+ return rv;
}
-
+}
+int fwp_endpoint_destroy(struct fwp_endpoint *epoint)
+{
+ epoint->status = FWP_EPOINT_CLOSED;
+ return 0;
}