]> rtime.felk.cvut.cz Git - frescor/fwp.git/commitdiff
Extended endpoint of mngt endpoint
authorMartin Molnar <molnar@sum.(none)>
Wed, 7 May 2008 16:25:52 +0000 (18:25 +0200)
committerMartin Molnar <molnar@sum.(none)>
Wed, 7 May 2008 16:25:52 +0000 (18:25 +0200)
fwp/lib/fwp_endpoint.c
fwp/lib/fwp_endpoint.h

index c4f29d76b7df76ff4f2dddd8c1766c51924b0bf1..6f521b929b20caec3eb95197b2556d8969418a0f 100644 (file)
@@ -5,6 +5,11 @@ typedef enum {
        FWP_RECV_EPOINT = 1,
 } fwp_endpoint_type_t;
 
+typedef enum {
+       FWP_EPOINT_DATA = 0,
+       FWP_EPOINT_MNGT = 1,
+} fwp_endpoint_flags_t;
+
 typedef enum {
        FWP_EPOINT_FREE         = 0,
        FWP_EPOINT_INACTIVE     = 1,
@@ -23,12 +28,14 @@ struct fwp_endpoint{
        /**< the vres descriptor the send endpoint is bound to */       
        fwp_vres_d_t            vresd;
        /**< for send enpoint it contains destination address
-        * for receive endpoint it is filled with the source address
+        * for receive endpoint it is filled with the msg source address
         */
        struct fwp_sockaddr     peer;   
-       /**< receive endpoint: port */
-       int                     port;
-       /**< receive endpoint: socket descriptor*/
+       /**<  port */
+       int                     port;   
+       /**< dest node */
+       int                     node;
+       /**< socket descriptor*/
        int                     sockd;  
        /**<specific operation options*/
        int                     flags;  
@@ -104,6 +111,7 @@ int fwp_send_endpoint_create(unsigned int node, unsigned int port, int flags,
 {      
        struct sockaddr_in *addr;
        fwp_endpoint_t *epoint;
+       int sockd;
 
        epoint = fwp_endpoint_alloc();  
         if (!epoint) {
@@ -111,32 +119,44 @@ int fwp_send_endpoint_create(unsigned int node, unsigned int port, int flags,
        }
        
        epoint->type = FWP_SEND_EPOINT;
-        epoint->peer.addrlen = sizeof(struct sockaddr_in);
        epoint->status = FWP_EPOINT_UNBOUND;
-       
+       epoint->node = node;
+       epoint->port = port;
+       epoint->flags = flags;
+               
        addr = (struct sockaddr_in *)&(epoint->peer.addr);
        addr->sin_family = AF_INET;
        addr->sin_addr.s_addr = node;
        addr->sin_port = htons(port);
+        epoint->peer.addrlen = sizeof(struct sockaddr_in);
        
-       if (flags && FWP_RELIABLE) {
-               if ((sockd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
-                       perror("Unable to open socket");
-                       return (-errno);
-               }
-       }else{
+       if (flags && FWP_EPOINT_MNGT) {
                if ((sockd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
                        perror("Unable to open socket");
-                       return (-errno);
+                       goto err;
                }
-               
 
+               if (connect(sockd,(struct sockaddr*) &epoint->peer.addr, 
+                               epoint->peer.addrlen)) {
+                       
+                       perror("Connect error");
+                       goto err;
+               }
 
+       } else {
+               if ((sockd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+                       perror("Unable to open socket");
+                       goto err;
+               }
        }
 
        FWP_DEBUG("Send endpoint created.\n"); 
        *epointdp = epoint;
+
        return 0;               
+err:
+       fwp_endpoint_free(epoint);
+       return (-errno);        
 }
 
 /**
@@ -148,10 +168,11 @@ int fwp_send_endpoint_create(unsigned int node, unsigned int port, int flags,
  * On error, negative error code is returned.
  *
  */
-int fwp_receive_endpoint_create(unsigned int port, fwp_endpoint_d_t *epointdp)
+int fwp_receive_endpoint_create(unsigned int port, int flags, fwp_endpoint_d_t *epointdp)
 {
        fwp_endpoint_t *epoint;
-       int rv;
+       int sockd;
+       struct sockaddr_in *addr;
        //int rcvbuf_size = 3000;
 
        epoint = fwp_endpoint_alloc();  
@@ -160,27 +181,72 @@ int fwp_receive_endpoint_create(unsigned int port, fwp_endpoint_d_t *epointdp)
        }
        
        epoint->type = FWP_RECV_EPOINT;
-       epoint->port = port;
        epoint->status = FWP_EPOINT_UNBOUND;
-       rv = fwp_create_inet_socket(port, 
-                       (struct sockaddr_in*)epoint->peer.addr);
-       if (rv < 0) { 
-               fwp_endpoint_free(epoint);
-               return rv;
-       }
+       epoint->flags  = flags;
+       
+       addr = (struct sockaddr_in *)&(epoint->peer.addr);
+       addr->sin_family = AF_INET;
+       addr->sin_addr.s_addr = INADDR_ANY;
+       addr->sin_port = htons(port);
+        epoint->peer.addrlen = sizeof(struct sockaddr_in);
        
-       epoint->sockd = rv;
+       if (flags && FWP_EPOINT_MNGT) {
+               if ((sockd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+                       perror("Unable to open socket");
+                       goto err;
+               }
+               
+               if (bind(sockd, (struct sockaddr*) &epoint->peer.addr,
+                       epoint->peer.addrlen) == -1) {
+                       
+                       perror("Bind error");
+                       goto err;
+               }
+
+               if (listen(sockd,0)) {
+                       perror("Connect error");
+                       goto err;
+               }
+
+       } else {
+               if ((sockd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+                       perror("Unable to open socket");
+                       goto err;
+               }
+               
+               if (bind(sockd, (struct sockaddr*) &epoint->peer.addr,
+                       epoint->peer.addrlen) == -1) {
+                       
+                       perror("Bind error");
+                       goto err;
+               }
+   
+       }
+
+       epoint->sockd = sockd;
        /*if (setsockopt(epoint->sockd, SOL_SOCKET, SO_RCVBUF, 
                        &rcvbuf_size, sizeof(rcvbuf_size)) == -1) {
                
                perror("Unable to set socket buffer size");
                return -1;
-       }*/
+       }else {
+               FWP_DEBUG("Receive endpoint buffer size is set.\n");
+       }
+       */
+       
+       getsockname(epoint->sockd, (struct sockaddr*)&epoint->peer.addr, 
+                       &epoint->peer.addrlen);
        
-       FWP_DEBUG("Receive endpoint buffer size is set.\n");
+       epoint->port = addr->sin_port;
        FWP_DEBUG("Receive endpoint port=%d created.\n", epoint->port); 
+       
        *epointdp = epoint; 
+       
        return 0;
+
+err:   
+       fwp_endpoint_free(epoint);
+       return (-errno);        
 }
 
 /**
index 45c1cce7ab7ca54431a005823a1f21ab93b80b23..6565be355174a9e348a0a4297fe4a9b96a20c0d6 100644 (file)
@@ -16,16 +16,13 @@ typedef struct fwp_endpoint* fwp_endpoint_d_t;
 #include "fwp_vres.h"
 
 int fwp_endpoint_table_init(unsigned int nr_endpoints);
-int fwp_send_endpoint_create(unsigned int node, unsigned int port, 
+int fwp_send_endpoint_create(unsigned int node, unsigned int port, int flags,
                                fwp_endpoint_d_t *epointdp);
-
-int fwp_send_endpoint_create(unsigned int node, unsigned int port,
-                               fwp_endpoint_d_t *epointdp);
-int fwp_receive_endpoint_create(unsigned int port, fwp_endpoint_d_t *epointdp);
+int fwp_receive_endpoint_create(unsigned int port, int flags, fwp_endpoint_d_t *epointdp);
 int fwp_send_endpoint_bind(fwp_endpoint_d_t epointd, fwp_vres_d_t vresd);
 int fwp_send_endpoint_unbind(fwp_endpoint_d_t epointd);
 
-/*int fwp_endpoint_setqpolicy(unsigne int epoint_id, qpolicy);*/
+/*int fwp_endpoint_setqpolicy(unsigned int epoint_id, qpolicy);*/
 /*int fwp_endpoint_setflags(unsigned int epoint_id, flags);*/
 
 ssize_t fwp_recv(fwp_endpoint_d_t epointd, void *buffer, size_t buffer_size);