Tcl Source Code

Hex Artifact Content
Login

Artifact 9dc6f5d624929d6942f198e5c9dcc47d15ffc0a5:

Attachment "generic_tclIOSock.c.patch" to ticket [1602520fff] added by stwo 2006-11-25 06:30:33.
0000: 2d 2d 2d 20 74 63 6c 49 4f 53 6f 63 6b 2e 63 2e  --- tclIOSock.c.
0010: 6f 72 69 67 09 4d 6f 6e 20 4a 75 6c 20 32 39 20  orig.Mon Jul 29 
0020: 31 32 3a 35 34 3a 34 31 20 32 30 30 32 0a 2b 2b  12:54:41 2002.++
0030: 2b 20 74 63 6c 49 4f 53 6f 63 6b 2e 63 09 46 72  + tclIOSock.c.Fr
0040: 69 20 4e 6f 76 20 32 34 20 31 37 3a 35 30 3a 34  i Nov 24 17:50:4
0050: 33 20 32 30 30 36 0a 40 40 20 2d 34 31 2c 32 33  3 2006.@@ -41,23
0060: 20 2b 34 31 2c 34 34 20 40 40 0a 20 20 20 20 20   +41,44 @@.     
0070: 63 68 61 72 20 2a 70 72 6f 74 6f 3b 09 09 2f 2a  char *proto;../*
0080: 20 22 74 63 70 22 20 6f 72 20 22 75 64 70 22 2c   "tcp" or "udp",
0090: 20 74 79 70 69 63 61 6c 6c 79 20 2a 2f 0a 20 20   typically */.  
00a0: 20 20 20 69 6e 74 20 2a 70 6f 72 74 50 74 72 3b     int *portPtr;
00b0: 09 09 2f 2a 20 52 65 74 75 72 6e 20 70 6f 72 74  ../* Return port
00c0: 20 6e 75 6d 62 65 72 20 2a 2f 0a 20 7b 0a 2d 20   number */. {.- 
00d0: 20 20 20 73 74 72 75 63 74 20 73 65 72 76 65 6e     struct serven
00e0: 74 20 2a 73 70 3b 09 09 2f 2a 20 50 72 6f 74 6f  t *sp;../* Proto
00f0: 63 6f 6c 20 69 6e 66 6f 20 66 6f 72 20 6e 61 6d  col info for nam
0100: 65 64 20 73 65 72 76 69 63 65 73 20 2a 2f 0a 2d  ed services */.-
0110: 20 20 20 20 54 63 6c 5f 44 53 74 72 69 6e 67 20      Tcl_DString 
0120: 64 73 3b 0a 2d 20 20 20 20 43 4f 4e 53 54 20 63  ds;.-    CONST c
0130: 68 61 72 20 2a 6e 61 74 69 76 65 3b 0a 2b 23 69  har *native;.+#i
0140: 66 64 65 66 20 48 41 56 45 5f 47 45 54 53 45 52  fdef HAVE_GETSER
0150: 56 42 59 4e 41 4d 45 5f 52 0a 2b 20 20 20 20 20  VBYNAME_R.+     
0160: 20 20 20 69 66 20 28 54 63 6c 5f 47 65 74 49 6e     if (Tcl_GetIn
0170: 74 28 4e 55 4c 4c 2c 20 73 74 72 69 6e 67 2c 20  t(NULL, string, 
0180: 70 6f 72 74 50 74 72 29 20 21 3d 20 54 43 4c 5f  portPtr) != TCL_
0190: 4f 4b 29 20 7b 0a 2b 09 09 2f 2a 0a 2b 09 09 20  OK) {.+../*.+.. 
01a0: 2a 20 44 6f 6e 27 74 20 62 6f 74 68 65 72 20 74  * Don't bother t
01b0: 72 61 6e 73 6c 61 74 69 6e 67 20 27 70 72 6f 74  ranslating 'prot
01c0: 6f 27 20 74 6f 20 6e 61 74 69 76 65 2e 0a 2b 09  o' to native..+.
01d0: 09 20 2a 2f 0a 2b 20 20 20 20 20 20 20 20 20 20  . */.+          
01e0: 20 20 20 20 20 20 73 74 72 75 63 74 20 73 65 72        struct ser
01f0: 76 65 6e 74 20 73 65 3b 20 20 20 20 20 20 2f 2a  vent se;      /*
0200: 20 50 72 6f 74 6f 63 6f 6c 20 69 6e 66 6f 20 66   Protocol info f
0210: 6f 72 20 6e 61 6d 65 64 20 73 65 72 76 69 63 65  or named service
0220: 73 20 2a 2f 0a 2b 20 20 20 20 20 20 20 20 20 20  s */.+          
0230: 20 20 20 20 20 20 73 74 72 75 63 74 20 73 65 72        struct ser
0240: 76 65 6e 74 5f 64 61 74 61 20 73 64 3b 20 2f 2a  vent_data sd; /*
0250: 20 4f 70 61 71 75 65 20 73 74 72 75 63 74 75 72   Opaque structur
0260: 65 20 75 73 65 64 20 62 79 20 67 65 74 73 65 72  e used by getser
0270: 76 65 6e 5f 72 20 2a 2f 0a 2b 20 20 20 20 20 20  ven_r */.+      
0280: 20 20 20 20 20 20 20 20 20 20 54 63 6c 5f 44 53            Tcl_DS
0290: 74 72 69 6e 67 20 6e 61 6d 65 3b 0a 20 0a 2d 20  tring name;. .- 
02a0: 20 20 20 69 66 20 28 54 63 6c 5f 47 65 74 49 6e     if (Tcl_GetIn
02b0: 74 28 4e 55 4c 4c 2c 20 73 74 72 69 6e 67 2c 20  t(NULL, string, 
02c0: 70 6f 72 74 50 74 72 29 20 21 3d 20 54 43 4c 5f  portPtr) != TCL_
02d0: 4f 4b 29 20 7b 0a 2d 09 2f 2a 0a 2d 09 20 2a 20  OK) {.-./*.-. * 
02e0: 44 6f 6e 27 74 20 62 6f 74 68 65 72 20 74 72 61  Don't bother tra
02f0: 6e 73 6c 61 74 69 6e 67 20 27 70 72 6f 74 6f 27  nslating 'proto'
0300: 20 74 6f 20 6e 61 74 69 76 65 2e 0a 2d 09 20 2a   to native..-. *
0310: 2f 0a 2d 09 20 0a 2d 09 6e 61 74 69 76 65 20 3d  /.-. .-.native =
0320: 20 54 63 6c 5f 55 74 66 54 6f 45 78 74 65 72 6e   Tcl_UtfToExtern
0330: 61 6c 44 53 74 72 69 6e 67 28 4e 55 4c 4c 2c 20  alDString(NULL, 
0340: 73 74 72 69 6e 67 2c 20 2d 31 2c 20 26 64 73 29  string, -1, &ds)
0350: 3b 0a 2d 09 73 70 20 3d 20 67 65 74 73 65 72 76  ;.-.sp = getserv
0360: 62 79 6e 61 6d 65 28 6e 61 74 69 76 65 2c 20 70  byname(native, p
0370: 72 6f 74 6f 29 3b 09 09 2f 2a 20 49 4e 54 4c 3a  roto);../* INTL:
0380: 20 4e 61 74 69 76 65 2e 20 2a 2f 0a 2d 09 54 63   Native. */.-.Tc
0390: 6c 5f 44 53 74 72 69 6e 67 46 72 65 65 28 26 64  l_DStringFree(&d
03a0: 73 29 3b 0a 2d 09 69 66 20 28 73 70 20 21 3d 20  s);.-.if (sp != 
03b0: 4e 55 4c 4c 29 20 7b 0a 2d 09 20 20 20 20 2a 70  NULL) {.-.    *p
03c0: 6f 72 74 50 74 72 20 3d 20 6e 74 6f 68 73 28 28  ortPtr = ntohs((
03d0: 75 6e 73 69 67 6e 65 64 20 73 68 6f 72 74 29 20  unsigned short) 
03e0: 73 70 2d 3e 73 5f 70 6f 72 74 29 3b 0a 2d 09 20  sp->s_port);.-. 
03f0: 20 20 20 72 65 74 75 72 6e 20 54 43 4c 5f 4f 4b     return TCL_OK
0400: 3b 0a 2d 09 7d 0a 2d 20 20 20 20 7d 0a 2b 20 20  ;.-.}.-    }.+  
0410: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 54 63                Tc
0420: 6c 5f 44 53 74 72 69 6e 67 49 6e 69 74 28 26 6e  l_DStringInit(&n
0430: 61 6d 65 29 3b 0a 2b 20 20 20 20 20 20 20 20 20  ame);.+         
0440: 20 20 20 20 20 20 20 54 63 6c 5f 55 74 66 54 6f         Tcl_UtfTo
0450: 45 78 74 65 72 6e 61 6c 44 53 74 72 69 6e 67 28  ExternalDString(
0460: 4e 55 4c 4c 2c 20 73 74 72 69 6e 67 2c 20 2d 31  NULL, string, -1
0470: 2c 20 26 6e 61 6d 65 29 3b 0a 2b 20 20 20 20 20  , &name);.+     
0480: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 73 64             /* sd
0490: 20 6e 65 65 64 73 20 74 6f 20 62 65 20 69 6e 69   needs to be ini
04a0: 74 69 61 6c 69 7a 65 64 2c 20 73 65 20 64 6f 65  tialized, se doe
04b0: 73 20 6e 6f 74 20 2a 2f 0a 2b 20 20 20 20 20 20  s not */.+      
04c0: 20 20 20 20 20 20 20 20 20 20 28 76 6f 69 64 29            (void)
04d0: 20 6d 65 6d 73 65 74 28 28 76 6f 69 64 20 2a 29   memset((void *)
04e0: 20 26 73 64 2c 20 30 2c 20 73 69 7a 65 6f 66 28   &sd, 0, sizeof(
04f0: 73 64 29 29 3b 0a 2b 20 20 20 20 20 20 20 20 20  sd));.+         
0500: 20 20 20 20 20 20 20 69 66 20 28 67 65 74 73 65         if (getse
0510: 72 76 62 79 6e 61 6d 65 5f 72 28 28 63 6f 6e 73  rvbyname_r((cons
0520: 74 20 63 68 61 72 20 2a 29 20 54 63 6c 5f 44 53  t char *) Tcl_DS
0530: 74 72 69 6e 67 56 61 6c 75 65 28 26 6e 61 6d 65  tringValue(&name
0540: 29 2c 20 70 72 6f 74 6f 2c 20 26 73 65 2c 20 26  ), proto, &se, &
0550: 73 64 29 20 3d 3d 20 30 29 20 7b 0a 2b 20 20 20  sd) == 0) {.+   
0560: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0570: 20 20 20 20 20 2a 70 6f 72 74 50 74 72 20 3d 20       *portPtr = 
0580: 6e 74 6f 68 73 28 28 75 6e 73 69 67 6e 65 64 20  ntohs((unsigned 
0590: 73 68 6f 72 74 29 20 73 65 2e 73 5f 70 6f 72 74  short) se.s_port
05a0: 29 3b 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20  );.+            
05b0: 20 20 20 20 20 20 20 20 20 20 20 20 54 63 6c 5f              Tcl_
05c0: 44 53 74 72 69 6e 67 46 72 65 65 28 26 6e 61 6d  DStringFree(&nam
05d0: 65 29 3b 0a 2b 20 20 20 20 20 20 20 20 20 20 20  e);.+           
05e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74               ret
05f0: 75 72 6e 20 54 43 4c 5f 4f 4b 3b 0a 2b 20 20 20  urn TCL_OK;.+   
0600: 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 2b               }.+
0610: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0620: 54 63 6c 5f 44 53 74 72 69 6e 67 46 72 65 65 28  Tcl_DStringFree(
0630: 26 6e 61 6d 65 29 3b 0a 2b 20 20 20 20 20 20 20  &name);.+       
0640: 20 7d 0a 2b 23 65 6c 73 65 0a 2b 20 20 20 20 20   }.+#else.+     
0650: 20 20 20 69 66 20 28 54 63 6c 5f 47 65 74 49 6e     if (Tcl_GetIn
0660: 74 28 4e 55 4c 4c 2c 20 73 74 72 69 6e 67 2c 20  t(NULL, string, 
0670: 70 6f 72 74 50 74 72 29 20 21 3d 20 54 43 4c 5f  portPtr) != TCL_
0680: 4f 4b 29 20 7b 0a 2b 09 09 2f 2a 0a 2b 09 09 20  OK) {.+../*.+.. 
0690: 2a 20 44 6f 6e 27 74 20 62 6f 74 68 65 72 20 74  * Don't bother t
06a0: 72 61 6e 73 6c 61 74 69 6e 67 20 27 70 72 6f 74  ranslating 'prot
06b0: 6f 27 20 74 6f 20 6e 61 74 69 76 65 2e 0a 2b 09  o' to native..+.
06c0: 09 20 2a 2f 0a 2b 20 20 20 20 20 20 20 20 20 20  . */.+          
06d0: 20 20 20 20 20 20 73 74 72 75 63 74 20 73 65 72        struct ser
06e0: 76 65 6e 74 20 2a 73 65 70 3b 20 20 20 20 2f 2a  vent *sep;    /*
06f0: 20 50 72 6f 74 6f 63 6f 6c 20 69 6e 66 6f 20 66   Protocol info f
0700: 6f 72 20 6e 61 6d 65 64 20 73 65 72 76 69 63 65  or named service
0710: 73 20 2a 2f 0a 2b 20 20 20 20 20 20 20 20 20 20  s */.+          
0720: 20 20 20 20 20 20 54 63 6c 5f 44 53 74 72 69 6e        Tcl_DStrin
0730: 67 20 6e 61 6d 65 3b 0a 2b 0a 2b 20 20 20 20 20  g name;.+.+     
0740: 20 20 20 20 20 20 20 20 20 20 20 54 63 6c 5f 44             Tcl_D
0750: 53 74 72 69 6e 67 49 6e 69 74 28 26 6e 61 6d 65  StringInit(&name
0760: 29 3b 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20  );.+            
0770: 20 20 20 20 54 63 6c 5f 55 74 66 54 6f 45 78 74      Tcl_UtfToExt
0780: 65 72 6e 61 6c 44 53 74 72 69 6e 67 28 4e 55 4c  ernalDString(NUL
0790: 4c 2c 20 73 74 72 69 6e 67 2c 20 2d 31 2c 20 26  L, string, -1, &
07a0: 6e 61 6d 65 29 3b 0a 2b 20 20 20 20 20 20 20 20  name);.+        
07b0: 20 20 20 20 20 20 20 20 73 65 70 20 3d 20 67 65          sep = ge
07c0: 74 73 65 72 76 62 79 6e 61 6d 65 28 28 63 6f 6e  tservbyname((con
07d0: 73 74 20 63 68 61 72 20 2a 29 20 54 63 6c 5f 44  st char *) Tcl_D
07e0: 53 74 72 69 6e 67 56 61 6c 75 65 28 26 6e 61 6d  StringValue(&nam
07f0: 65 29 2c 20 70 72 6f 74 6f 29 3b 09 09 2f 2a 20  e), proto);../* 
0800: 49 4e 54 4c 3a 20 4e 61 74 69 76 65 2e 20 2a 2f  INTL: Native. */
0810: 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .+              
0820: 20 20 54 63 6c 5f 44 53 74 72 69 6e 67 46 72 65    Tcl_DStringFre
0830: 65 28 26 6e 61 6d 65 29 3b 0a 2b 20 20 20 20 20  e(&name);.+     
0840: 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 73             if (s
0850: 65 70 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 20  ep != NULL) {.+ 
0860: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0870: 20 20 20 20 20 20 20 2a 70 6f 72 74 50 74 72 20         *portPtr 
0880: 3d 20 6e 74 6f 68 73 28 28 75 6e 73 69 67 6e 65  = ntohs((unsigne
0890: 64 20 73 68 6f 72 74 29 20 73 65 70 2d 3e 73 5f  d short) sep->s_
08a0: 70 6f 72 74 29 3b 0a 2b 20 20 20 20 20 20 20 20  port);.+        
08b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
08c0: 72 65 74 75 72 6e 20 54 43 4c 5f 4f 4b 3b 0a 2b  return TCL_OK;.+
08d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
08e0: 7d 0a 2b 20 20 20 20 20 20 20 20 7d 0a 2b 23 65  }.+        }.+#e
08f0: 6e 64 69 66 20 2f 2a 20 48 41 56 45 5f 47 45 54  ndif /* HAVE_GET
0900: 53 45 52 56 42 59 4e 41 4d 45 5f 52 20 2a 2f 0a  SERVBYNAME_R */.
0910: 20 20 20 20 20 69 66 20 28 54 63 6c 5f 47 65 74       if (Tcl_Get
0920: 49 6e 74 28 69 6e 74 65 72 70 2c 20 73 74 72 69  Int(interp, stri
0930: 6e 67 2c 20 70 6f 72 74 50 74 72 29 20 21 3d 20  ng, portPtr) != 
0940: 54 43 4c 5f 4f 4b 29 20 7b 0a 20 09 72 65 74 75  TCL_OK) {. .retu
0950: 72 6e 20 54 43 4c 5f 45 52 52 4f 52 3b 0a 20 20  rn TCL_ERROR;.  
0960: 20 20 20 7d 0a                                      }.