[PATCH] packet: create packet.dll and Implement PacketGetAdapterNames(try 5)

Jianqiu Zhang zhangjianqiu13 at gmail.com
Wed Feb 24 23:44:09 CST 2016


Hi Andre



> some blank lines would be great above, also we normally use a space between C keywords (if, while, ...) and the parenthesis
>
>> +    {
>> +        /* Work around bug in libpcap ptr->description == NULL when no description got */
>> +        if(ptr->description == NULL)
>> +        {
>> +            ptr->description = (char *)HeapAlloc(GetProcessHeap(), 0, sizeof(char));
>> +            *(ptr->description) = '\0';
>
> Can't we simply use a static const "" here? That also would avoid the hack later to free the heap space

Yes, I can use char empty_str[] = '" to avoid the memory alloc , but I
also need to do the ptr->description = NULL when clean up
, Or it will crash when calling pcap_freealldevs, Is there any way not
to make ptr->description = NULL and avoid the crash? Thanks

>
>> +        }
>> +
>> +        min_name_size += strlen(ptr->name) + 1;
>> +        min_desc_size += strlen(ptr->description) + 1;
>> +        ptr = ptr->next;
>> +    }
>> +
>> +    min_size = min_name_size + min_desc_size + 2;
>> +
>> +    if(!name_list || *size < min_size)
>> +    {
>> +        ptr = alldevs;
>> +        while(ptr)
>> +        {
>> +            if(!strcmp(ptr->description, ""))
>> +            {
>> +                HeapFree(GetProcessHeap(), 0, ptr->description);
>> +                ptr->description = NULL;
>> +            }
>> +            ptr = ptr->next;
>> +        }
>> +        SetLastError(ERROR_INSUFFICIENT_BUFFER);
>> +        pcap_freealldevs(alldevs);
>> +        *size = min_size;
>> +        return FALSE;
>> +    }
>> +    ptr = alldevs;
>> +    desc_offset = name_offset = 0;
>> +    while(ptr)
>> +    {
>> +        strcpy(name_list + name_offset, ptr->name);
>> +        strcpy(name_list + min_name_size + desc_offset + 1, ptr->description);
>> +        name_offset += strlen(ptr->name) + 1;
>> +        desc_offset += strlen(ptr->description) + 1;
>> +
>> +        /* Work around bug in libpcap ptr->description == NULL when no description got */
>> +        if(!strcmp(ptr->description, ""))
>> +        {
>> +            HeapFree(GetProcessHeap(), 0, ptr->description);
>> +            ptr->description = NULL;
>> +        }
>> +        ptr = ptr->next;
>> +    }
>> +    name_list[min_name_size] = '\0';
>> +    name_list[min_size - 1] = '\0';
>> +
>> +    pcap_freealldevs(alldevs);
>> +    return TRUE;
>> +}
>> diff --git a/dlls/packet/packet.spec b/dlls/packet/packet.spec
>> new file mode 100644
>> index 0000000..32b9bc0
>> --- /dev/null
>> +++ b/dlls/packet/packet.spec
>> @@ -0,0 +1,32 @@
>> +@ stub PacketAllocatePacket
>> +@ stub PacketCloseAdapter
>> +@ stub PacketFreePacket
>> +@ cdecl PacketGetAdapterNames(ptr ptr)
>> +@ stub PacketGetAirPcapHandle
>> +@ stub PacketGetDriverVersion
>> +@ stub PacketGetNetInfoEx
>> +@ stub PacketGetNetType
>> +@ stub PacketGetReadEvent
>> +@ stub PacketGetStats
>> +@ stub PacketGetStatsEx
>> +@ stub PacketGetVersion
>> +@ stub PacketInitPacket
>> +@ stub PacketIsDumpEnded
>> +@ stub PacketLibraryVersion
>> +@ stub PacketOpenAdapter
>> +@ stub PacketReceivePacket
>> +@ stub PacketRequest
>> +@ stub PacketSendPacket
>> +@ stub PacketSendPackets
>> +@ stub PacketSetBpf
>> +@ stub PacketSetBuff
>> +@ stub PacketSetDumpLimits
>> +@ stub PacketSetDumpName
>> +@ stub PacketSetHwFilter
>> +@ stub PacketSetLoopbackBehavior
>> +@ stub PacketSetMinToCopy
>> +@ stub PacketSetMode
>> +@ stub PacketSetNumWrites
>> +@ stub PacketSetReadTimeout
>> +@ stub PacketSetSnapLen
>> +@ stub PacketStopDriver
>> diff --git a/dlls/wpcap/Makefile.in b/dlls/wpcap/Makefile.in
>> index 91b4a95..e9794cf 100644
>> --- a/dlls/wpcap/Makefile.in
>> +++ b/dlls/wpcap/Makefile.in
>> @@ -1,6 +1,7 @@
>>  MODULE    = wpcap.dll
>>  DELAYIMPORTS = ws2_32
>>  EXTRALIBS = $(PCAP_LIBS)
>> +IMPORTLIB = wpcap
>>
>>  C_SRCS = \
>>       wpcap.c
>> --
>> 2.7.1
>>
>
>
>



More information about the wine-devel mailing list