fix OneNAND erase/write
[qemu] / slirp / udp.c
index 3f0c08b..11e78cd 100644 (file)
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
@@ -67,7 +63,7 @@ static void udp_emu(struct socket *so, struct mbuf *m);
 struct socket *udp_last_so = &udb;
 
 void
-udp_init()
+udp_init(void)
 {
        udb.so_next = udb.so_prev = &udb;
 }
@@ -76,9 +72,7 @@ udp_init()
  * ip->ip_len length data (IPDU)
  */
 void
-udp_input(m, iphlen)
-       register struct mbuf *m;
-       int iphlen;
+udp_input(register struct mbuf *m, int iphlen)
 {
        register struct ip *ip;
        register struct udphdr *uh;
@@ -136,8 +130,7 @@ udp_input(m, iphlen)
         * Checksum extended UDP header and data.
         */
        if (UDPCKSUM && uh->uh_sum) {
-         ((struct ipovly *)ip)->ih_next = 0;
-         ((struct ipovly *)ip)->ih_prev = 0;
+      memset(&((struct ipovly *)ip)->ih_mbuf, 0, sizeof(struct mbuf_ptr));
          ((struct ipovly *)ip)->ih_x1 = 0;
          ((struct ipovly *)ip)->ih_len = uh->uh_ulen;
          /* keep uh_sum for ICMP reply
@@ -158,6 +151,9 @@ udp_input(m, iphlen)
             goto bad;
         }
 
+        if (slirp_restrict)
+            goto bad;
+
         /*
          *  handle TFTP
          */
@@ -280,7 +276,7 @@ int udp_output2(struct socket *so, struct mbuf *m,
         * and addresses and length put into network format.
         */
        ui = mtod(m, struct udpiphdr *);
-       ui->ui_next = ui->ui_prev = 0;
+    memset(&ui->ui_i.ih_mbuf, 0 , sizeof(struct mbuf_ptr));
        ui->ui_x1 = 0;
        ui->ui_pr = IPPROTO_UDP;
        ui->ui_len = htons(m->m_len - sizeof(struct ip)); /* + sizeof (struct udphdr)); */
@@ -322,7 +318,7 @@ int udp_output(struct socket *so, struct mbuf *m,
         if ((so->so_faddr.s_addr & htonl(0x000000ff)) == htonl(0xff))
             saddr.sin_addr.s_addr = alias_addr.s_addr;
         else if (addr->sin_addr.s_addr == loopback_addr.s_addr ||
-                 ((so->so_faddr.s_addr & htonl(CTL_DNS)) == htonl(CTL_DNS)))
+                 (ntohl(so->so_faddr.s_addr) & 0xff) != CTL_ALIAS)
             saddr.sin_addr.s_addr = so->so_faddr.s_addr;
     }
     daddr.sin_addr = so->so_laddr;
@@ -332,8 +328,7 @@ int udp_output(struct socket *so, struct mbuf *m,
 }
 
 int
-udp_attach(so)
-     struct socket *so;
+udp_attach(struct socket *so)
 {
   struct sockaddr_in addr;
 
@@ -365,8 +360,7 @@ udp_attach(so)
 }
 
 void
-udp_detach(so)
-       struct socket *so;
+udp_detach(struct socket *so)
 {
        closesocket(so->s);
        /* if (so->so_m) m_free(so->so_m);    done by sofree */
@@ -410,7 +404,7 @@ static void
 udp_emu(struct socket *so, struct mbuf *m)
 {
        struct sockaddr_in addr;
-        int addrlen = sizeof(addr);
+       socklen_t addrlen = sizeof(addr);
 #ifdef EMULATE_TALK
        CTL_MSG_OLD *omsg;
        CTL_MSG *nmsg;
@@ -475,14 +469,14 @@ struct cu_header {
                        type = omsg->type;
                        OTOSIN(omsg, ctl_addr)->sin_port = addr.sin_port;
                        OTOSIN(omsg, ctl_addr)->sin_addr = our_addr;
-                       strncpy(omsg->l_name, getlogin(), NAME_SIZE_OLD);
+                        pstrcpy(omsg->l_name, NAME_SIZE_OLD, getlogin());
                } else {                /* new talk */
                        omsg = (CTL_MSG_OLD *) buff;
                        nmsg = mtod(m, CTL_MSG *);
                        type = nmsg->type;
                        OTOSIN(nmsg, ctl_addr)->sin_port = addr.sin_port;
                        OTOSIN(nmsg, ctl_addr)->sin_addr = our_addr;
-                       strncpy(nmsg->l_name, getlogin(), NAME_SIZE_OLD);
+                        pstrcpy(nmsg->l_name, NAME_SIZE_OLD, getlogin());
                }
 
                if (type == LOOK_UP)
@@ -633,15 +627,11 @@ struct cu_header {
 }
 
 struct socket *
-udp_listen(port, laddr, lport, flags)
-       u_int port;
-       u_int32_t laddr;
-       u_int lport;
-       int flags;
+udp_listen(u_int port, u_int32_t laddr, u_int lport, int flags)
 {
        struct sockaddr_in addr;
        struct socket *so;
-       int addrlen = sizeof(struct sockaddr_in), opt = 1;
+       socklen_t addrlen = sizeof(struct sockaddr_in), opt = 1;
 
        if ((so = socreate()) == NULL) {
                free(so);