Changeset 5500

Show
Ignore:
Timestamp:
06/06/12 19:22:29 (7 years ago)
Author:
cmatthew
Message:

Added the getifaddrs system call.

Location:
seattle/branches/nacl_repy/seattlelib
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • seattle/branches/nacl_repy/seattlelib/dispatcher.repy

    r5334 r5500  
    4949    45:lind_safe_net_shutdown, 
    5050    46:lind_safe_net_select, 
     51    47:lind_safe_net_getifaddrs, 
    5152 
    5253    105:lind_comp_cia, 
     
    9798    45:lind_net_shutdown, 
    9899    46:lind_net_select, 
     100    47:lind_net_getifaddrs, 
    99101 
    100102    105:lind_comp_cia, 
  • seattle/branches/nacl_repy/seattlelib/lind_net_calls.py

    r5334 r5500  
    324324 
    325325    try: 
    326       log(str(filedescriptortable[fd])) 
    327326      # BUG: The timeout it configurable, right? 
    328327      newsockobj = openconnection(remoteip, remoteport, localip, int(localport), 10) 
     
    940939 
    941940    if optname == SO_ERROR: 
    942       log("Warning: returning fake error value.")  
     941      assert False, "returning a fake error." 
    943942      tmp = filedescriptortable[fd]['errno'] 
    944943      filedescriptortable[fd]['errno'] = 0 
     
    11211120  #   mark false 
    11221121  # if read works, do it as a peek, so next time it won't block 
    1123   raise UnimplementedError("CM: Don't call this. It is still being tested!!") 
     1122  log("Warning: Don't call this. It is still being tested!!") 
    11241123 
    11251124  retval = 0 
     
    11851184 
    11861185 
     1186def getifaddrs_syscall(): 
     1187  """  
     1188    http://linux.die.net/man/2/getifaddrs 
     1189 
     1190    Returns a list of the IP addresses of this machine. 
     1191 
     1192    Fake most of the values.  I dont think an overly restrictive 
     1193    netmask is going to cause problems? 
     1194  """ 
     1195  try: 
     1196    ip = getmyip() 
     1197  except: 
     1198    raise SyscallError("getifaddrs syscall","EADDRNOTAVAIL","Problem getting the" \ 
     1199                       " local ip address.") 
     1200  broadcast = (ip.split('.')[0:3]) # the broadcast address is just x.y.z.255? 
     1201  broadcast = '.'.join(broadcast + ['255'])  
     1202  return 0, [{'ifa_name':'eth0', 
     1203           'ifa_flags':0, 
     1204           'ifa_addr':ip, 
     1205           'ifa_netmask':'255.255.255.0',  
     1206           'ifa_broadaddr':broadcast, 
     1207          }, 
     1208 
     1209          {'ifa_name':'lo0', 
     1210           'ifa_flags':0, 
     1211           'ifa_addr':'127.0.0.1', 
     1212           'ifa_netmask':'255.0.0.0', 
     1213           'ifa_broadaddr':'127.0.0.1', 
     1214          } 
     1215          ] 
     1216 
    11871217 
    11881218# int socketpair(int domain, int type, int protocol, int socket_vector[2]); 
     
    12001230  a,b,c,d = struct_unpack("<B<B<B<B",ipaddress) 
    12011231  return str(a) + "." + str(b) + "." +str(c) + "." +str(d)  
     1232 
     1233 
     1234def inet_aton(ipaddress): 
     1235  """ 
     1236  Convert an IP address in string format to its integer octet format 
     1237   
     1238  """ 
     1239  return struct_unpack("<I",struct_pack("<B<B<B<B",*map(int, ipaddress.split("."))))[0]