int network_init(t_ivac *ivac) {
- sockaddr_in addr;
+ struct sockaddr_in addr;
puts("[ivac] inet: initializing network ...");
return ERROR;
}
- printf("[ivac] inet: listen on %s port %d.\n",inet_ntoa(addr.sin_addr.s_addr)
+ printf("[ivac] inet: listen on %s port %d.\n",inet_ntoa(addr.sin_addr)
,ivac->net.l_port);
return SUCCESS;
int network_manage_connection(t_ivac *ivac) {
int i;
- sockaddr_in addr;
+ struct sockaddr_in addr;
for(i=0;i<MAX_CONNECTIONS;i++) {
memset(&addr,0,sizeof(struct sockaddr));
addr.sin_family=AF_INET;
addr.sin_port=htons(ivac->net.connection[i].port);
- addr.sin_addr_s_addr=inet_aton(ivac->net.connection[i].ip);
+ if(!inet_aton(ivac->net.connection[i].ip,&(addr.sin_addr))) {
+ perror("[ivac] inet.c: inet_aton call");
+ return ERROR;
+ }
if(connect(ivac->net.connection[i].fd,(struct sockaddr *)&addr,
sizeof(struct sockaddr))==-1) {
return SUCCESS;
}
+
+int network_manage_incoming(t_ivac *ivac) {
+
+ int i;
+ struct sockaddr_in addr;
+ int len;
+
+ for(i=0;i<MAX_CONNECTIONS;i++) {
+ if(!ivac->net.connection[i].status&C_IN_USE) {
+ if((ivac->net.connection[i].fd=accept(ivac->net.l_fd,
+ (struct sockaddr *)&addr,
+ &len))==-1) {
+ perror("[ivac] inet.c: accept call");
+ return ERROR;
+ }
+ strncpy(ivac->net.connection[i].ip,inet_ntoa(addr.sin_addr),IP_DIGITS);
+ ivac->net.connection[i].port=ntohs(addr.sin_port);
+ ivac->net.connection[i].status=C_IN_USE|C_INFO_A|C_SOCKET|C_ESTABL;
+ return i;
+ }
+ }
+
+ puts("[ivac] inet: maximum connections reached");
+ return ERROR;
+}
int network_send(int fd,unsigned char *data,int datasize) {