struct socket * soCloneUDPSocketWithForegnAddr(PNATState pData, bool fBindSocket, struct socket *pSo, uint32_t u32ForeignAddr) { struct socket *pNewSocket = NULL; LogFlowFunc(("Enter: fBindSocket:%RTbool, so:%R[natsock], u32ForeignAddr:%RTnaipv4\n", fBindSocket, pSo, u32ForeignAddr)); pNewSocket = socreate(); if (!pNewSocket) { LogFunc(("Can't create socket\n")); LogFlowFunc(("Leave: NULL\n")); return NULL; } if (fBindSocket) { if (udp_attach(pData, pNewSocket, 0) <= 0) { sofree(pData, pNewSocket); LogFunc(("Can't attach fresh created socket\n")); return NULL; } } else { pNewSocket->so_cloneOf = (struct socket *)pSo; pNewSocket->s = pSo->s; insque(pData, pNewSocket, &udb); } pNewSocket->so_laddr = pSo->so_laddr; pNewSocket->so_lport = pSo->so_lport; pNewSocket->so_faddr.s_addr = u32ForeignAddr; pNewSocket->so_fport = pSo->so_fport; pSo->so_cCloneCounter++; LogFlowFunc(("Leave: %R[natsock]\n", pNewSocket)); return pNewSocket; }
void m_free(struct mbuf *m) { DEBUG_CALL("m_free"); DEBUG_ARG("m = %lx", (long )m); if(m) { if (m->m_flags & M_USEDLIST) remque(m); if (m->m_flags & M_EXT) free(m->m_ext); if (m->m_flags & M_DOFREE) { free(m); mbuf_alloced--; } else if ((m->m_flags & M_FREELIST) == 0) { insque(m,&m_freelist); m->m_flags = M_FREELIST; } } }
static int icmp_send(struct socket *so, struct mbuf *m, int hlen) { struct ip *ip = mtod(m, struct ip *); struct sockaddr_in addr; so->s = qemu_socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP); if (so->s == -1) { return -1; } so->so_m = m; so->so_faddr = ip->ip_dst; so->so_laddr = ip->ip_src; so->so_iptos = ip->ip_tos; so->so_type = IPPROTO_ICMP; so->so_state = SS_ISFCONNECTED; so->so_expire = curtime + SO_EXPIRE; addr.sin_family = AF_INET; addr.sin_addr = so->so_faddr; insque(so, &so->slirp->icmp); if (sendto(so->s, m->m_data + hlen, m->m_len - hlen, 0, (struct sockaddr *)&addr, sizeof(addr)) == -1) { DEBUG_MISC((dfd, "icmp_input icmp sendto tx errno = %d-%s\n", errno, strerror(errno))); icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno)); icmp_detach(so); } return 0; }
void push_event(TimeoutEvent *event, Queue *queue) { TimeoutEvent *stepper = queue->last; event->prev = event->next = NULL; oma_debug_print("Pushing to queue...\n"); fflush(stdout); if (stepper == NULL) { queue->first = queue->last = event; } else { while (stepper != NULL && timecmp(stepper->time, event->time) <= 0) { stepper = stepper->prev; } if (stepper == NULL) { queue->first->prev = event; event->next = queue->first; queue->first = event; } else { insque(event, stepper); if (event->next == NULL) { queue->last = event; } } } queue->size++; }
int udp_attach(struct socket *so) { struct sockaddr_in addr; if((so->s = socket(AF_INET,SOCK_DGRAM,0)) != -1) { /* * Here, we bind() the socket. Although not really needed * (sendto() on an unbound socket will bind it), it's done * here so that emulation of ytalk etc. don't have to do it */ addr.sin_family = AF_INET; addr.sin_port = 0; addr.sin_addr.s_addr = INADDR_ANY; if(bind(so->s, (struct sockaddr *)&addr, sizeof(addr))<0) { int lasterrno=errno; closesocket(so->s); so->s=-1; #ifdef _WIN32 WSASetLastError(lasterrno); #else errno=lasterrno; #endif } else { /* success, insert in queue */ so->so_expire = curtime + SO_EXPIRE; insque(so,&udb); } } return(so->s); }
int Lpx_PCB_alloc( struct socket *so, struct lpxpcb *head, struct proc *td ) { register struct lpxpcb *lpxp; DEBUG_CALL(4, ("Lpx_PCB_alloc\n")); MALLOC(lpxp, struct lpxpcb *, sizeof *lpxp, M_PCB, M_WAITOK); if (lpxp == NULL) { DEBUG_CALL(0, ("Lpx_PCB_alloc:==> Failed\n")); return (ENOBUFS); } bzero(lpxp, sizeof(*lpxp)); lpxp->lpxp_socket = so; if (lpxcksum) lpxp->lpxp_flags |= LPXP_CHECKSUM; read_random(&lpxp->lpxp_messageid, sizeof(lpxp->lpxp_messageid)); insque(lpxp, head); so->so_pcb = (caddr_t)lpxp; so->so_options |= SO_DONTROUTE; return (0); }
void m_free(struct mbuf *m) { DEBUG_CALL("m_free"); DEBUG_ARG("m = %p", m); if(m) { /* Remove from m_usedlist */ if (m->m_flags & M_USEDLIST) remque(m); /* If it's M_EXT, free() it */ if (m->m_flags & M_EXT) free(m->m_ext); /* * Either free() it or put it on the free list */ if (m->m_flags & M_DOFREE) { m->slirp->mbuf_alloced--; free(m); } else if ((m->m_flags & M_FREELIST) == 0) { insque(m,&m->slirp->m_freelist); m->m_flags = M_FREELIST; /* Clobber other flags */ } } /* if(m) */ }
/* * Get an mbuf from the free list, if there are none * malloc one * * Because fragmentation can occur if we alloc new mbufs and * free old mbufs, we mark all mbufs above mbuf_thresh as M_DOFREE, * which tells m_free to actually free() it */ struct mbuf * m_get() { register struct mbuf *m; int flags = 0; DEBUG_CALL("m_get"); if (m_freelist.m_next == &m_freelist) { m = (struct mbuf *)malloc(msize); if (m == NULL) goto end_error; mbuf_alloced++; if (mbuf_alloced > mbuf_thresh) flags = M_DOFREE; if (mbuf_alloced > mbuf_max) mbuf_max = mbuf_alloced; } else { m = m_freelist.m_next; remque(m); } /* Insert it in the used list */ insque(m,&m_usedlist); m->m_flags = (flags | M_USEDLIST); /* Initialise it */ m->m_size = msize - sizeof(struct m_hdr); m->m_data = m->m_dat; m->m_len = 0; m->m_nextpkt = 0; m->m_prevpkt = 0; end_error: DEBUG_ARG("m = %lx", (long )m); return m; }
struct mbuf * m_get(void) { register struct mbuf *m; int flags = 0; DEBUG_CALL("m_get"); if (m_freelist.m_next == &m_freelist) { m = (struct mbuf *)malloc(SLIRP_MSIZE); if (m == NULL) goto end_error; mbuf_alloced++; if (mbuf_alloced > MBUF_THRESH) flags = M_DOFREE; if (mbuf_alloced > mbuf_max) mbuf_max = mbuf_alloced; } else { m = m_freelist.m_next; remque(m); } insque(m,&m_usedlist); m->m_flags = (flags | M_USEDLIST); m->m_size = SLIRP_MSIZE - sizeof(struct m_hdr); m->m_data = m->m_dat; m->m_len = 0; m->m_nextpkt = NULL; m->m_prevpkt = NULL; end_error: DEBUG_ARG("m = %lx", (long )m); return m; }
struct qbuf * str2qb (char *s, int len, int head) { struct qbuf *qb, *pb; if ((pb = (struct qbuf *) malloc ((unsigned) (sizeof *pb + len))) == NULL) return NULL; if (head) { if ((qb = (struct qbuf *) malloc (sizeof *qb)) == NULL) { free ((char *) pb); return NULL; } qb -> qb_forw = qb -> qb_back = qb; qb -> qb_data = NULL, qb -> qb_len = len; insque (pb, qb); } else { pb -> qb_forw = pb -> qb_back = pb; qb = pb; } pb -> qb_data = pb -> qb_base; if ((pb -> qb_len = len) > 0 && s) bcopy (s, pb -> qb_data, len); return qb; }
int udp_attach(PNATState pData, struct socket *so) { struct sockaddr_in *addr; struct sockaddr sa_addr; socklen_t socklen = sizeof(struct sockaddr); int status; int opt = 1; /* We attaching some olready attched socket ??? */ Assert(so->so_type == 0); if ((so->s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) goto error; /* * Here, we bind() the socket. Although not really needed * (sendto() on an unbound socket will bind it), it's done * here so that emulation of ytalk etc. don't have to do it */ memset(&sa_addr, 0, sizeof(struct sockaddr)); addr = (struct sockaddr_in *)&sa_addr; #ifdef RT_OS_DARWIN addr->sin_len = sizeof(struct sockaddr_in); #endif addr->sin_family = AF_INET; addr->sin_addr.s_addr = pData->bindIP.s_addr; fd_nonblock(so->s); if (bind(so->s, &sa_addr, sizeof(struct sockaddr_in)) < 0) { int lasterrno = errno; closesocket(so->s); so->s = -1; #ifdef RT_OS_WINDOWS WSASetLastError(lasterrno); #else errno = lasterrno; #endif goto error; } /* success, insert in queue */ so->so_expire = curtime + SO_EXPIRE; /* enable broadcast for later use */ setsockopt(so->s, SOL_SOCKET, SO_BROADCAST, (const char *)&opt, sizeof(opt)); status = getsockname(so->s, &sa_addr, &socklen); Assert(status == 0 && sa_addr.sa_family == AF_INET); so->so_hlport = ((struct sockaddr_in *)&sa_addr)->sin_port; so->so_hladdr.s_addr = ((struct sockaddr_in *)&sa_addr)->sin_addr.s_addr; SOCKET_LOCK_CREATE(so); QSOCKET_LOCK(udb); insque(pData, so, &udb); NSOCK_INC(); QSOCKET_UNLOCK(udb); so->so_type = IPPROTO_UDP; return so->s; error: Log2(("NAT: can't create datagramm socket\n")); return -1; }
static int do_test (void) { struct qelem elements[4]; int ret = 0; /* Linear list. */ memset (elements, 0xff, sizeof (elements)); insque (&elements[0], NULL); remque (&elements[0]); insque (&elements[0], NULL); insque (&elements[2], &elements[0]); insque (&elements[1], &elements[0]); insque (&elements[3], &elements[2]); remque (&elements[2]); insque (&elements[2], &elements[0]); CHECK (elements[0].q_back == NULL); CHECK (elements[0].q_forw == &elements[2]); CHECK (elements[1].q_back == &elements[2]); CHECK (elements[1].q_forw == &elements[3]); CHECK (elements[2].q_back == &elements[0]); CHECK (elements[2].q_forw == &elements[1]); CHECK (elements[3].q_back == &elements[1]); CHECK (elements[3].q_forw == NULL); /* Circular list. */ memset (elements, 0xff, sizeof (elements)); elements[0].q_back = &elements[0]; elements[0].q_forw = &elements[0]; insque (&elements[2], &elements[0]); insque (&elements[1], &elements[0]); insque (&elements[3], &elements[2]); remque (&elements[2]); insque (&elements[2], &elements[0]); CHECK (elements[0].q_back == &elements[3]); CHECK (elements[0].q_forw == &elements[2]); CHECK (elements[1].q_back == &elements[2]); CHECK (elements[1].q_forw == &elements[3]); CHECK (elements[2].q_back == &elements[0]); CHECK (elements[2].q_forw == &elements[1]); CHECK (elements[3].q_back == &elements[1]); CHECK (elements[3].q_forw == &elements[0]); return ret; }
int udp_attach(struct socket *so) { if((so->s = qemu_socket(AF_INET,SOCK_DGRAM,0)) != -1) { so->so_expire = curtime + SO_EXPIRE; insque(so, &so->slirp->udb); } return(so->s); }
void testValues() { f = 2; int result; insque(anyque(), anyque()); //@ assert f == 2; //@ assert vacuous: \false; }
/* * Insert a log record struct on the log buffer struct. The log buffer * has a pointer to the head of a queue of log records that have been * read from the buffer file but have not been processed yet because * the record id did not match the sequence desired for processing. * The insertion must be in the 'correct'/sorted order which adds * to the complexity of this function. */ static void insert_lrp_to_lb(struct nfslog_buf *lbp, struct nfslog_lr *lrp) { int ins_rec_id = lrp->log_record.re_header.rh_rec_id; struct nfslog_lr *curlrp; if (lbp->lrps == NULL) { /* that was easy */ lbp->lrps = lrp; } else { /* * Does this lrp go before the first on the list? * If so, do the insertion by hand since insque is not * as flexible when queueing an element to the head of * a list. */ if (ins_rec_id < lbp->lrps->log_record.re_header.rh_rec_id) { lrp->next = lbp->lrps; lrp->prev = lbp->lrps->prev; lbp->lrps->prev->next = lrp; lbp->lrps->prev = lrp; lbp->lrps = lrp; } else { /* * Search the queue for the correct insertion point. * Be careful about the insque so that the record * ends up in the right place. */ curlrp = lbp->lrps; do { if (ins_rec_id < curlrp->next->log_record.re_header.rh_rec_id) break; curlrp = curlrp->next; } while (curlrp != lbp->lrps); if (curlrp == lbp->lrps) insque(lrp, lbp->lrps->prev); else insque(lrp, curlrp); } } /* always keep track of how many we have */ lbp->num_lrps++; }
/* * XXX This should really be tcp_listen */ struct socket * solisten(u_int port, u_int32_t laddr, u_int lport, int flags) { SockAddress addr; uint32_t addr_ip; struct socket *so; int s; DEBUG_CALL("solisten"); DEBUG_ARG("port = %d", port); DEBUG_ARG("laddr = %x", laddr); DEBUG_ARG("lport = %d", lport); DEBUG_ARG("flags = %x", flags); if ((so = socreate()) == NULL) { /* free(so); Not sofree() ??? free(NULL) == NOP */ return NULL; } /* Don't tcp_attach... we don't need so_snd nor so_rcv */ if ((so->so_tcpcb = tcp_newtcpcb(so)) == NULL) { free(so); return NULL; } insque(so,&tcb); /* * SS_FACCEPTONCE sockets must time out. */ if (flags & SS_FACCEPTONCE) so->so_tcpcb->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT*2; so->so_state = (SS_FACCEPTCONN|flags); so->so_laddr_port = lport; /* Kept in host format */ so->so_laddr_ip = laddr; /* Ditto */ so->so_haddr_port = port; s = socket_loopback_server( port, SOCKET_STREAM ); if (s < 0) return NULL; socket_get_address(s, &addr); so->so_faddr_port = sock_address_get_port(&addr); addr_ip = (uint32_t) sock_address_get_ip(&addr); if (addr_ip == 0 || addr_ip == loopback_addr_ip) so->so_faddr_ip = alias_addr_ip; else so->so_faddr_ip = addr_ip; so->s = s; return so; }
int udp_attach(struct socket *so) { so->s = socket_anyaddr_server( 0, SOCKET_DGRAM ); if (so->s != -1) { /* success, insert in queue */ so->so_expire = curtime + SO_EXPIRE; insque(so,&udb); } return(so->s); }
/* Free all the data cache blocks, thus discarding all cached data. */ static void dcache_flush () { register struct dcache_block *db; while ((db = dcache_valid.next) != &dcache_valid) { remque (db); insque (db, &dcache_free); } }
void mutexwait(struct _pcb * p, struct _mtx * m) { /** store mutex address in efwm */ p->pcb$l_efwm = m; // check. 32 bit problem /** new pcb state MWAIT */ p->pcb$w_state = SCH$C_MWAIT; /** insert into MWAIT scheduling queue */ insque(p,sch$aq_wqhdr[SCH$C_MWAIT].wqh$l_wqfl); int ipl=getipl(); /** put on wait */ sch$waitl(p, &sch$aq_wqhdr[SCH$C_MWAIT]); setipl(ipl); }
int Lpx_PCB_alloc( struct socket *so, struct lpxpcb *head, struct proc *td ) { register struct lpxpcb *lpxp; DEBUG_PRINT(DEBUG_MASK_PCB_TRACE, ("Lpx_PCB_alloc\n")); MALLOC(lpxp, struct lpxpcb *, sizeof *lpxp, M_PCB, M_WAITOK); if (lpxp == NULL) { DEBUG_PRINT(DEBUG_MASK_PCB_ERROR, ("Lpx_PCB_alloc:==> Failed\n")); return (ENOBUFS); } bzero(lpxp, sizeof(*lpxp)); lpxp->lpxp_socket = so; if (lpxcksum) lpxp->lpxp_flags |= LPXP_CHECKSUM; read_random(&lpxp->lpxp_messageid, sizeof(lpxp->lpxp_messageid)); lck_rw_lock_exclusive(head->lpxp_list_rw); insque(lpxp, head); lck_rw_unlock_exclusive(head->lpxp_list_rw); lpxp->lpxp_head = head; so->so_pcb = (caddr_t)lpxp; //so->so_options |= SO_DONTROUTE; if (so->so_proto->pr_flags & PR_PCBLOCK) { if (head == &lpx_stream_pcb) { lpxp->lpxp_mtx = lck_mtx_alloc_init(stream_mtx_grp, stream_mtx_attr); lpxp->lpxp_mtx_grp = stream_mtx_grp; } else { lpxp->lpxp_mtx = lck_mtx_alloc_init(datagram_mtx_grp, datagram_mtx_attr); lpxp->lpxp_mtx_grp = datagram_mtx_grp; } if (lpxp->lpxp_mtx == NULL) { DEBUG_PRINT(DEBUG_MASK_PCB_ERROR, ("Lpx_PCB_alloc: can't alloc mutex! so=%p\n", so)); FREE(lpxp, M_PCB); return(ENOMEM); } } return (0); }
/* * Initialize "ifentry". * (get information of each interface) */ void ifconfig() #ifdef HAVE_GETIFADDRS { extern struct ifinfo *ifentry; struct ifaddrs *ifap, *ifa; struct sockaddr_in6 *sin6; struct ifinfo *ife; int s; if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) fatal("<ifconfig>: socket"); if (getifaddrs(&ifap)) fatal("<ifconfig>: getifaddrs"); for (ifa = ifap; ifa; ifa = ifa->ifa_next) { if (ifa->ifa_addr->sa_family == AF_INET6) { sin6 = (struct sockaddr_in6 *)ifa->ifa_addr; if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { if ((ife = find_if_by_name(ifa->ifa_name)) == NULL) { /* ifreq */ /* new interface */ MALLOC(ife, struct ifinfo); MALLOC(ife->ifi_ifn, struct if_nameindex); ife->ifi_ifn->if_index = if_nametoindex(ifa->ifa_name); ife->ifi_ifn->if_name = (char *)malloc(strlen(ifa->ifa_name) +1); strcpy(ife->ifi_ifn->if_name, ifa->ifa_name); get_ifinfo(ife); if (ifentry != NULL) { /* (global) */ insque(ife, ifentry); } else { ife->ifi_next = ife; ife->ifi_prev = ife; ifentry = ife; } } else { if (!IN6_IS_ADDR_UNSPECIFIED(&ife->ifi_laddr)) fatalx("<ifconfig>: link-local address cannot be doubly defined"); } memcpy(&ife->ifi_laddr, &sin6->sin6_addr, sizeof(struct in6_addr)); #ifdef ADVANCEDAPI CLEAR_IN6_LINKLOCAL_IFINDEX(&ife->ifi_laddr);/* Toshiba's IPv6 macro */ #endif }
static void request_failed(dhcp_smach_t *dsmp) { PKT_LIST *offer; dsmp->dsm_server = ipv6_all_dhcp_relay_and_servers; if ((offer = select_best(dsmp)) != NULL) { insque(offer, &dsmp->dsm_recv_pkt_list); dhcp_requesting(NULL, dsmp); } else { dhcpmsg(MSG_INFO, "no offers left on %s; restarting", dsmp->dsm_name); dhcp_selecting(dsmp); } }
int udp_attach(PNATState pData, struct socket *so) { struct sockaddr sa_addr; socklen_t socklen = sizeof(struct sockaddr); int status; int opt = 1; AssertReturn(so->so_type == 0, -1); so->so_type = IPPROTO_UDP; so->s = socket(AF_INET, SOCK_DGRAM, 0); if (so->s == -1) goto error; fd_nonblock(so->s); so->so_sottl = 0; so->so_sotos = 0; so->so_sodf = -1; status = sobind(pData, so); if (status != 0) return status; /* success, insert in queue */ so->so_expire = curtime + SO_EXPIRE; /* enable broadcast for later use */ setsockopt(so->s, SOL_SOCKET, SO_BROADCAST, (const char *)&opt, sizeof(opt)); status = getsockname(so->s, &sa_addr, &socklen); if (status == 0) { Assert(sa_addr.sa_family == AF_INET); so->so_hlport = ((struct sockaddr_in *)&sa_addr)->sin_port; so->so_hladdr.s_addr = ((struct sockaddr_in *)&sa_addr)->sin_addr.s_addr; } SOCKET_LOCK_CREATE(so); QSOCKET_LOCK(udb); insque(pData, so, &udb); NSOCK_INC(); QSOCKET_UNLOCK(udb); return so->s; error: Log2(("NAT: can't create datagram socket\n")); return -1; }
/* returns -1 in case of error */ int pipe_list_push_cmd (cmd_line_t *cmd_line, const char *cmd_str, size_t n) { struct qelem *nelem = new_qelem (cmd_str, n); sysfail (nelem==NULL, -1); if (strlen (nelem->q_data) == 0) { free (nelem->q_data); free (nelem); return EMPTY_LINE; } insque (nelem, cmd_line->pipe_list_tail); cmd_line->pipe_list_tail = nelem; if (cmd_line->pipe_list_head == NULL) cmd_line->pipe_list_head = cmd_line->pipe_list_tail; return EXIT_SUCCESS; }
struct socket * udp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr, u_int lport, int flags) { struct sockaddr_in addr; struct socket *so; socklen_t addrlen = sizeof(struct sockaddr_in); so = socreate(slirp); if (!so) { return NULL; } so->s = qemu_socket(AF_INET,SOCK_DGRAM,0); so->so_expire = curtime + SO_EXPIRE; insque(so, &slirp->udb); addr.sin_family = AF_INET; addr.sin_addr.s_addr = haddr; addr.sin_port = hport; if (bind(so->s,(struct sockaddr *)&addr, addrlen) < 0) { udp_detach(so); return NULL; } socket_set_fast_reuse(so->s); getsockname(so->s,(struct sockaddr *)&addr,&addrlen); so->so_fport = addr.sin_port; if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == loopback_addr.s_addr) { so->so_faddr = slirp->vhost_addr; } else { so->so_faddr = addr.sin_addr; } so->so_lport = lport; so->so_laddr.s_addr = laddr; if (flags != SS_FACCEPTONCE) so->so_expire = 0; so->so_state &= SS_PERSISTENT_MASK; so->so_state |= SS_ISFCONNECTED | flags; return so; }
struct assocblk *newacblk () { register struct assocblk *acb; acb = (struct assocblk *) calloc (1, sizeof *acb); if (acb == NULL) return NULL; acb -> acb_fd = NOTOK; acb -> acb_actno = 1; if (once_only == 0) { ACHead -> acb_forw = ACHead -> acb_back = ACHead; once_only++; } insque (acb, ACHead -> acb_back); return acb; }
void addrouteforif(struct interface *ifp) { struct sockaddr_ipx net; struct sockaddr *dst; struct rt_entry *rt; if (ifp->int_flags & IFF_POINTOPOINT) { int (*match)(); struct interface *ifp2 = ifnet; dst = &ifp->int_dstaddr; /* Search for interfaces with the same net */ ifp->int_sq.n = ifp->int_sq.p = &(ifp->int_sq); match = afswitch[dst->sa_family].af_netmatch; if (match) for (ifp2 = ifnet; ifp2; ifp2 =ifp2->int_next) { if ((ifp->int_flags & IFF_POINTOPOINT) == 0) continue; if ((*match)(&ifp2->int_dstaddr,&ifp->int_dstaddr)) { insque(&ifp2->int_sq,&ifp->int_sq); break; } } } else { bzero(&net, sizeof(net)); net.sipx_family = AF_IPX; net.sipx_len = sizeof (net); net.sipx_addr.x_net = satoipx_addr(ifp->int_broadaddr).x_net; dst = (struct sockaddr *)&net; } rt = rtlookup(dst); if (rt) rtdelete(rt); if (tracing) fprintf(stderr, "Adding route to interface %s\n", ifp->int_name); if (ifp->int_transitions++ > 0) syslog(LOG_ERR, "re-installing interface %s", ifp->int_name); rtadd(dst, &ifp->int_addr, ifp->int_metric, 0, ifp->int_flags & (IFF_INTERFACE|IFF_PASSIVE|IFF_REMOTE)); }
struct socket * udp_listen(u_int port, u_int32_t laddr, u_int lport, int flags) { struct socket *so; SockAddress addr; uint32_t addr_ip; if ((so = socreate()) == NULL) { free(so); return NULL; } so->s = socket_anyaddr_server( port, SOCKET_DGRAM ); so->so_expire = curtime + SO_EXPIRE; so->so_haddr_port = port; insque(so,&udb); if (so->s < 0) { udp_detach(so); return NULL; } socket_get_address(so->s, &addr); so->so_faddr_port = sock_address_get_port(&addr); addr_ip = sock_address_get_ip(&addr); if (addr_ip == 0 || addr_ip == loopback_addr_ip) so->so_faddr_ip = alias_addr_ip; else so->so_faddr_ip = addr_ip; so->so_laddr_port = lport; so->so_laddr_ip = laddr; if (flags != SS_FACCEPTONCE) so->so_expire = 0; so->so_state = SS_ISFCONNECTED; return so; }
static __inline__ void _delayed_call_enqueue( queue_t queue, timer_call_t call) { timer_call_t current; current = TC(queue_first(queue)); while (TRUE) { if ( queue_end(queue, qe(current)) || call->deadline < current->deadline ) { current = TC(queue_prev(qe(current))); break; } current = TC(queue_next(qe(current))); } insque(qe(call), qe(current)); call->state = DELAYED; }
/* * Get an mbuf from the free list, if there are none * malloc one * * Because fragmentation can occur if we alloc new mbufs and * free old mbufs, we mark all mbufs above mbuf_thresh as M_DOFREE, * which tells m_free to actually free() it */ struct mbuf * m_get(Slirp *slirp) { register struct mbuf *m; int flags = 0; DEBUG_CALL("m_get"); if (slirp->m_freelist.m_next == &slirp->m_freelist) { m = (struct mbuf *)malloc(SLIRP_MSIZE); if (m == NULL) goto end_error; slirp->mbuf_alloced++; if (slirp->mbuf_alloced > MBUF_THRESH) flags = M_DOFREE; m->slirp = slirp; } else { m = slirp->m_freelist.m_next; remque(m); } /* Insert it in the used list */ insque(m,&slirp->m_usedlist); m->m_flags = (flags | M_USEDLIST); /* Initialise it */ m->m_size = SLIRP_MSIZE - offsetof(struct mbuf, m_dat); m->m_data = m->m_dat; m->m_len = 0; m->m_nextpkt = NULL; m->m_prevpkt = NULL; m->arp_requested = false; m->expiration_date = (uint64_t)-1; end_error: DEBUG_ARG("m = %p", m); return m; }