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,
/**< 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;
{
struct sockaddr_in *addr;
fwp_endpoint_t *epoint;
+ int sockd;
epoint = fwp_endpoint_alloc();
if (!epoint) {
}
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);
}
/**
* 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();
}
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);
}
/**
#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);