daily pastebin goal
42%
SHARE
TWEET

Untitled

a guest Jan 21st, 2018 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def get_mtu(self):
  2.     '''Use socket ioctl call to get MTU size'''
  3.     s = socket.socket(type=socket.SOCK_DGRAM)
  4.     ifr = self.ifname + '\x00'*(32-len(self.ifname))
  5.     try:
  6.         ifs = ioctl(s, SIOCGIFMTU, ifr)
  7.         mtu = struct.unpack('<H',ifs[16:18])[0]
  8.     except Exception, s:
  9.         logger.critical('socket ioctl call failed: {0}'.format(s))
  10.         raise
  11.  
  12.     logger.debug('get_mtu: mtu of {0} = {1}'.format(self.ifname, mtu))
  13.     self.mtu = mtu
  14.     return mtu
  15.  
  16.  def set_mtu(self, mtu):
  17.     '''Use socket ioctl call to set MTU size'''
  18.     s = socket.socket(type=socket.SOCK_DGRAM)
  19.     ifr = struct.pack('<16sH', self.ifname, mtu) + '\x00'*14
  20.     try:
  21.         ifs = ioctl(s, SIOCSIFMTU, ifr)
  22.         self.mtu = struct.unpack('<H',ifs[16:18])[0]
  23.     except Exception, s:
  24.         logger.critical('socket ioctl call failed: {0}'.format(s))
  25.         raise
  26.  
  27.     logger.debug('set_mtu: mtu of {0} = {1}'.format(self.ifname, self.mtu))
  28.  
  29.     return self.mtu
RAW Paste Data
Top