int so_accept(int fd, uchar *raddr, ushort *rport) { int nfd; socklen_t len; struct sockaddr sa; struct sockaddr_in *sin; sin = (struct sockaddr_in*)&sa; len = sizeof(sa); osenter(); if(doselect(fd) < 0) { osleave(); return -1; } nfd = accept(fd, &sa, &len); osleave(); if(nfd < 0) oserror(); if(sin->sin_family != AF_INET || len != sizeof(*sin)) error(Enotv4); ipw6(raddr, sin->sin_addr.s_addr); *rport = nhgets(&sin->sin_port); return nfd; }
int so_accept(int fd, unsigned long *raddr, unsigned short *rport) { int nfd, len; struct sockaddr sa; struct sockaddr_in *sin; sin = (struct sockaddr_in*)&sa; len = sizeof(sa); osenter(); if(doselect(fd) < 0) { osleave(); return -1; } nfd = accept(fd, &sa, &len); osleave(); if(nfd < 0) oserror(); if(sin->sin_family != AF_INET || len != sizeof(*sin)) error("not AF_INET"); *raddr = nhgetl(&sin->sin_addr.s_addr); *rport = nhgets(&sin->sin_port); return nfd; }
int so_recv(int sock, void *va, int len, void *hdr, int hdrlen) { int r, l; struct sockaddr sa; struct sockaddr_in *sin; char h[Udphdrlen]; osenter(); if(doselect(sock) < 0) { osleave(); return -1; } if(hdr == 0) r = recv(sock, va, len, 0); else { sin = (struct sockaddr_in*)&sa; l = sizeof(sa); r = recvfrom(sock, va, len, 0, &sa, &l); if(r >= 0) { memset(h, sizeof h, 0); switch(hdrlen){ case OUdphdrlenv4: memmove(h, &sin->sin_addr, 4); memmove(h+2*IPv4addrlen, &sin->sin_port, 2); break; case OUdphdrlen: v4tov6(h, (uchar*)&sin->sin_addr); memmove(h+2*IPaddrlen, &sin->sin_port, 2); break; default: v4tov6(h, (uchar*)&sin->sin_addr); memmove(h+3*IPaddrlen, &sin->sin_port, 2); break; } /* alas there's no way to get the local addr/port correctly. Pretend. */ getsockname(sock, &sa, &l); switch(hdrlen){ case OUdphdrlenv4: memmove(h+IPv4addrlen, &sin->sin_addr, IPv4addrlen); memmove(h+2*IPv4addrlen+2, &sin->sin_port, 2); break; case OUdphdrlen: v4tov6(h+IPaddrlen, (uchar*)&sin->sin_addr); memmove(h+2*IPaddrlen+2, &sin->sin_port, 2); break; default: v4tov6(h+IPaddrlen, (uchar*)&sin->sin_addr); v4tov6(h+2*IPaddrlen, (uchar*)&sin->sin_addr); /* ifcaddr */ memmove(h+3*IPaddrlen+2, &sin->sin_port, 2); break; } memmove(hdr, h, hdrlen); } } osleave(); return r; }
char check_char(char* input){ if(input != NULL){ if(my_strcmp(input, KU) == 0){ moveup(); }else if(my_strcmp(input, KD) == 0){ movedown(); }else if(my_strcmp(input, KL) == 0){ moveleft(); }else if(my_strcmp(input, KR) == 0){ moveright(); }else if(my_strcmp(input, " ") == 0){ doselect(); }else{ getout(input); } } return *input; }
/* check_char.c pre: Takes a char* c post: Takes action based upon what key is pressed */ char check_char(char* str){ if(str){ if(!(my_strcmp(str, "\n\0"))) return 2; else if(!(my_strcmp(str, ESC))) return 1; else if (!(my_strcmp(str, KU))) moveup(); else if (!(my_strcmp(str, KD))) movedown(); else if (!(my_strcmp(str, KL))) moveleft(); else if (!(my_strcmp(str, KR))) moveright(); else if (!(my_strcmp(str, " \0"))) doselect(); return 0; } return -1; }
void check_char(char *c) { if(!my_strcmp(c, (char *) SPACE)) doselect(); else if(!my_strcmp(c, gl_env.left)) moveleft(); else if(!my_strcmp(c, gl_env.right)) moveright(); else if(!my_strcmp(c, gl_env.up)) moveup(); else if(!my_strcmp(c, gl_env.down)) movedown(); else if(!my_strcmp(c, gl_env.esc) || !my_strcmp(c, (char *)ESC)) { restore_terminal(); getout(0); exit(1); } else if(!my_strcmp(c, (char *) ENTER)) { restore_terminal(); getout(1); } }
void StateGraphParser::seenselect( iter_t s, iter_t f) { std::string state_id(s,f); doselect(state_id); }