setladdrport()

setladdrport()

概要

引数

  • c -- Conv
  • str
  • announcing

実装

  813: /*
  814:  *  set a local address and port from a string of the form
  815:  *      [address!]port[!r]
  816:  */
  817: char*
  818: setladdrport(Conv* c, char* str, int announcing)
  819: {
  820:         char *p;
  821:         char *rv;
  822:         ushort lport;
  823:         uchar addr[IPaddrlen];
  824: 
  825:         rv = nil;
  826: 
  827:         /*
  828:          *  ignore restricted part if it exists.  it's
  829:          *  meaningless on local ports.
  830:          */
  831:         p = strchr(str, '!');
  832:         if(p != nil){
  833:                 *p++ = 0;
  834:                 if(strcmp(p, "r") == 0)
  835:                         p = nil;
  836:         }
  837: 
  838:         c->lport = 0;
  839:         if(p == nil){
  840:                 if(announcing)
  841:                         ipmove(c->laddr, IPnoaddr);
  842:                 else
  843:                         setladdr(c);
  844:                 p = str;
  845:         } else {
  846:                 if(strcmp(str, "*") == 0)
  847:                         ipmove(c->laddr, IPnoaddr);
  848:                 else {
  849:                         parseip(addr, str);
  850:                         if(ipforme(c->p->f, addr))
  851:                                 ipmove(c->laddr, addr);
  852:                         else
  853:                                 return "not a local IP address";
  854:                 }
  855:         }
  856: 
  857:         /* one process can get all connections */
  858:         if(announcing && strcmp(p, "*") == 0){
  859:                 if(!iseve())
  860:                         error(Eperm);
  861:                 return setluniqueport(c, 0);
  862:         }
  863: 
  864:         lport = atoi(p);
  865:         if(lport <= 0)
  866:                 setlport(c);
  867:         else
  868:                 rv = setluniqueport(c, lport);
  869:         return rv;
  870: }