×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Feb 2007
    Posts
    7

    With ctypes & open c, get MTU value success but set MTU fail /* Permission denied */

    I want decrease my WLAN mtu to 1492.

    Now I can retrieve MTU value by ioctl. But when I try SIOCSIFMTU it return permission error.

    why? Do I have to sign my python script ? ( I run it under PythonScriptShell)

    Code:
    from _ctypes import *
    from ctypes import *
    from struct import *
    libc = dlopen("libc.dll")
    
    ntohl   = lambda x:     call_function(dlsym(libc, "168"),   (x,))
    ntohs   = lambda x:     call_function(dlsym(libc, "169"),   (x,))
    print ntohs(1), ntohl(256)  # simple test 
    
    socket  = lambda x,y,z: call_function(dlsym(libc, "339"),   (x,y,z))
    ioctl   = lambda x,y,z: call_function(dlsym(libc, "180"),   (x,y,z))
    close   = lambda x:     call_function(dlsym(libc, "57"),    (x,))
    perror  = lambda x:     call_function(dlsym(libc, "255"),   (x,))
    dup     = lambda x:     call_function(dlsym(libc, "67"),    (x,))
    close(2)
    dup(1) #let perror() print errmsg to stdout
    
    
    SIZEOF_IFREQ = 84
    SIZEOF_IFCONF = 8
    IFREQ_IDXFMT = '52sH'
    IFREQ_MTUFMT = '52sI'
    IFREQ_FLAGSFMT = '52sBB'
    autopadding = lambda start, size: start + str(size - calcsize(start)) + 's'
    ifreq_idxfmt = autopadding(IFREQ_IDXFMT, SIZEOF_IFREQ)
    ifreq_mtufmt = autopadding(IFREQ_MTUFMT, SIZEOF_IFREQ)
    ifreq_flagsfmt = autopadding(IFREQ_FLAGSFMT, SIZEOF_IFREQ)
    
    IOCPARM_MASK = 0x1fff
    _IOC = lambda inout,group,num,len: (inout | (len & IOCPARM_MASK) << 16 | ord(group) << 8 | num)
    _IOR = lambda group, num, len: _IOC(0x40000000L, group, num, len)
    _IOW = lambda group, num, len: _IOC(0x80000000L, group, num, len)
    _IOWR = lambda group, num, len: _IOC(0x40000000L|0x80000000L, group, num, len)
    
    SIOCGIFCONF     = _IOWR('s', 3, SIZEOF_IFCONF)
    SIOCGIFFLAGS    = _IOWR('i', 17, SIZEOF_IFREQ)
    SIOCGIFMTU      = _IOWR('i', 51, SIZEOF_IFREQ)
    SIOCSIFMTU      = _IOW('i', 52, SIZEOF_IFREQ)
    
    IFF_UP          = 0x1
    
    AF_INET         = 0x0800
    SOCK_DGRAM      = 2
    IPPROTO_UDP     = 17
    
    sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
    
    result = create_string_buffer(SIZEOF_IFREQ * 20)
    ifc = create_string_buffer(pack("II", SIZEOF_IFREQ * 20, addressof(result)), SIZEOF_IFCONF)
    
    ret = ioctl(sockfd, SIOCGIFCONF, ifc)
    ifc_len, ifc_buf = unpack("II", ifc.raw)
    count = ifc_len / SIZEOF_IFREQ
    for i in range(0, ifc_len, SIZEOF_IFREQ):
        ifreq = result.raw[i:i+SIZEOF_IFREQ]
        ifr_name, ifr_idx, padding = unpack(ifreq_idxfmt, ifreq)
        ifr = create_string_buffer(ifr_name, SIZEOF_IFREQ)
        ret = ioctl(sockfd, SIOCGIFFLAGS, ifr)
        ifr_name, ifr_flags, ifr_flagshigh, padding = unpack(ifreq_flagsfmt, ifr)
        if not (ifr_flags & IFF_UP):
            print "%s: DOWN" % ifr_name
            continue
        ret = ioctl(sockfd, SIOCGIFMTU, ifr)
        ifr_name, ifr_mtu, padding = unpack(ifreq_mtufmt, ifr)
        print "%s: UP, MTU: %d" % (ifr_name, ifr_mtu)
        if ifr_mtu == 1500:
            ifr = create_string_buffer(pack(ifreq_mtufmt, ifr_name, 1492, padding), SIZEOF_IFREQ)
            if -1 == ioctl(sockfd, SIOCSIFMTU, ifr): foo = perror("why")

  2. #2
    Registered User
    Join Date
    Feb 2007
    Posts
    7

    Re: With ctypes & open c, get MTU value success but set MTU fail /* Permission denied

    This page said that changing MTU need NetworkControl capability.

    Should I resign libffi & _ctypes & MyPySIS package? Howto get the privilege free?

  3. #3
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: With ctypes & open c, get MTU value success but set MTU fail /* Permission denied

    Quote Originally Posted by qyb View Post
    This page said that changing MTU need NetworkControl capability.

    Should I resign libffi & _ctypes & MyPySIS package? Howto get the privilege free?
    Hi qyb

    If you are talking about signing your sis file with the network services capability then you can do that in symbian open signed.

    Hope this helps you
    Enjoy Pythoning
    Gaba88

  4. #4
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,796

    Re: With ctypes & open c, get MTU value success but set MTU fail /* Permission denied

    Quote Originally Posted by qyb View Post
    This page said that changing MTU need NetworkControl capability.

    Should I resign libffi & _ctypes & MyPySIS package? Howto get the privilege free?
    You cannot resign the files using open signed online. You need pure unsigned files to get it signed through open signed online. First you should remove the current signatures, and then finally sign the unsigned file via open signed online with ""All capabilities""...

    How to update an old extension ?

    Best Regards,
    Croozeus
    Pankaj Nathani
    www.croozeus.com

  5. #5
    Registered User
    Join Date
    Feb 2005
    Location
    Belgium (Europe)
    Posts
    1,352

    Re: With ctypes & open c, get MTU value success but set MTU fail /* Permission denied

    Hello Qyb ,

    MTU means Maximum Transmission Unit
    It seems that you want to modify the standard MTU Windows or Ethernet 1500 to 1492 (WiFi) like HERE

    You could also wrap this C++ function : TL2CapConfig::SetMaxTransmitUnitSize()
    in a PyS60 extension for change this MTU value.

    @gaba88,croozeus : Don't mistake the NetworkServices(self-signed) capability with the NetworkControl(It's a restricted capability not available in the opensigned capabilities set !)

    So it seems impossible to use socket because you can't have NetworkControl with the opensigned way !

    BR
    Cyke64
    pys60 1.4.5 and 2.0.0, pygame, PyS60 CE on E90 and 5800 !

    Find my pys60 extension modules on cyke64.googlepages.com

  6. #6
    Registered User
    Join Date
    Feb 2007
    Posts
    7

    Re: With ctypes & open c, get MTU value success but set MTU fail /* Permission denied

    Quote Originally Posted by gaba88 View Post
    Hi qyb

    If you are talking about signing your sis file with the network services capability then you can do that in symbian open signed.

    Hope this helps you
    Enjoy Pythoning
    Gaba88
    Thanks.

    Now I do verify that changing MTU need NetworkControl capability. I resign PythonScriptShell & libffi & _ctypes package, then my script run well.

    The free Open Sign service does not support NetworkControl capability. I got a personal-IMEI dev cert to do it.

    Anyway, OpenC + ctypes is very cool.
    Last edited by qyb; 2008-10-08 at 11:58.

  7. #7
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: With ctypes & open c, get MTU value success but set MTU fail /* Permission denied

    Quote Originally Posted by cyke64 View Post
    Hello Qyb ,

    @gaba88,croozeus : Don't mistake the NetworkServices(self-signed) capability with the NetworkControl(It's a restricted capability not available in the opensigned capabilities set !)

    BR
    Cyke64
    Hi Cyke

    Thanks for letting me know the difference between the NetworkServices and NetworkControl capabilities actually i thought that in the beginning only but was not sure.

    Thanks
    Gaba88

Similar Threads

  1. Virtual Com Ports from Digianswer software.
    By mareksuski in forum Bluetooth Technology
    Replies: 3
    Last Post: 2002-06-27, 09:49

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×