| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 821 人关注过本帖
标题:请大侠们帮忙写出这段代码!!(已解决)
取消只看楼主 加入收藏
yrt888
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-3-7
收藏
 问题点数:0 回复次数:1 
请大侠们帮忙写出这段代码!!(已解决)
这是一段VC代码,我实在不懂,请大侠们将他写成VFP的,万分感激!

#include <winsock2.h>
#include <ws2tcpip.h>

#include <iphlpapi.h>

#include <stdio.h>
#include <stdlib.h>

#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
/* Note: could also use malloc() and free() */

int main()
{

    // Declare and initialize variables.

    DWORD dwSize = 0;
    DWORD dwRetVal = 0;

    int i, j;

    /* variables used for GetIfTable and GetIfEntry */
    MIB_IFTABLE *pIfTable;
    MIB_IFROW *pIfRow;

    // Allocate memory for our pointers.
    pIfTable = (MIB_IFTABLE *) MALLOC(sizeof (MIB_IFTABLE));
    if (pIfTable == NULL) {
        printf("Error allocating memory needed to call GetIfTable\n");
        return 1;
    }
    // Make an initial call to GetIfTable to get the
    // necessary size into dwSize
    dwSize = sizeof (MIB_IFTABLE);
    if (GetIfTable(pIfTable, &dwSize, FALSE) == ERROR_INSUFFICIENT_BUFFER) {
        FREE(pIfTable);
        pIfTable = (MIB_IFTABLE *) MALLOC(dwSize);
        if (pIfTable == NULL) {
            printf("Error allocating memory needed to call GetIfTable\n");
            return 1;
        }
    }
    // Make a second call to GetIfTable to get the actual
    // data we want.
    if ((dwRetVal = GetIfTable(pIfTable, &dwSize, FALSE)) == NO_ERROR) {
        printf("\tNum Entries: %ld\n\n", pIfTable->dwNumEntries);
        for (i = 0; i < (int) pIfTable->dwNumEntries; i++) {
            pIfRow = (MIB_IFROW *) & pIfTable->table[i];
            printf("\tIndex[%d]:\t %ld\n", i, pIfRow->dwIndex);
            printf("\tInterfaceName[%d]:\t %ws", i, pIfRow->wszName);
            printf("\n");
            printf("\tDescription[%d]:\t ", i);
            for (j = 0; j < (int) pIfRow->dwDescrLen; j++)
                printf("%c", pIfRow->bDescr[j]);
            printf("\n");
            printf("\tType[%d]:\t ", i);
            switch (pIfRow->dwType) {
            case IF_TYPE_OTHER:
                printf("Other\n");
                break;
            case IF_TYPE_ETHERNET_CSMACD:
                printf("Ethernet\n");
                break;
            case IF_TYPE_ISO88025_TOKENRING:
                printf("Token Ring\n");
                break;
            case IF_TYPE_PPP:
                printf("PPP\n");
                break;
            case IF_TYPE_SOFTWARE_LOOPBACK:
                printf("Software Lookback\n");
                break;
            case IF_TYPE_ATM:
                printf("ATM\n");
                break;
            case IF_TYPE_IEEE80211:
                printf("IEEE 802.11 Wireless\n");
                break;
            case IF_TYPE_TUNNEL:
                printf("Tunnel type encapsulation\n");
                break;
            case IF_TYPE_IEEE1394:
                printf("IEEE 1394 Firewire\n");
                break;
            default:
                printf("Unknown type %ld\n", pIfRow->dwType);
                break;
            }
            printf("\tMtu[%d]:\t\t %ld\n", i, pIfRow->dwMtu);
            printf("\tSpeed[%d]:\t %ld\n", i, pIfRow->dwSpeed);
            printf("\tPhysical Addr:\t ");
            if (pIfRow->dwPhysAddrLen == 0)
                printf("\n");
            for (j = 0; j < (int) pIfRow->dwPhysAddrLen; j++) {
                if (j == (pIfRow->dwPhysAddrLen - 1))
                    printf("%.2X\n", (int) pIfRow->bPhysAddr[j]);
                else
                    printf("%.2X-", (int) pIfRow->bPhysAddr[j]);
            }
            printf("\tAdmin Status[%d]:\t %ld\n", i, pIfRow->dwAdminStatus);
            printf("\tOper Status[%d]:\t ", i);
            switch (pIfRow->dwOperStatus) {
            case IF_OPER_STATUS_NON_OPERATIONAL:
                printf("Non Operational\n");
                break;
            case IF_OPER_STATUS_UNREACHABLE:
                printf("Unreachable\n");
                break;
            case IF_OPER_STATUS_DISCONNECTED:
                printf("Disconnected\n");
                break;
            case IF_OPER_STATUS_CONNECTING:
                printf("Connecting\n");
                break;
            case IF_OPER_STATUS_CONNECTED:
                printf("Connected\n");
                break;
            case IF_OPER_STATUS_OPERATIONAL:
                printf("Operational\n");
                break;
            default:
                printf("Unknown status %ld\n", pIfRow->dwAdminStatus);
                break;
            }
            printf("\n");
        }
    } else {
        printf("GetIfTable failed with error: \n", dwRetVal);
        if (pIfTable != NULL) {
            FREE(pIfTable);
            pIfTable = NULL;
        }  
        return 1;
        // Here you can use FormatMessage to find out why
        // it failed.
    }
    if (pIfTable != NULL) {
        FREE(pIfTable);
        pIfTable = NULL;
    }
    return 0;
}

希望各位大侠帮忙一下,小弟衷心多谢!

[[it] 本帖最后由 yrt888 于 2008-3-22 18:09 编辑 [/it]]
搜索更多相关主题的帖子: 代码 
2008-03-21 12:40
yrt888
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-3-7
收藏
得分:0 
我在网上找到一段VFP代码,作者说收发字节相等,说明有错,希望大侠们指正,谢谢!

参考网上资料,
http://www.
http://bbs.
写成如下代码,感觉不对,因为发送和接收字节数一样,肯定有不对的地方,希望各位网友参谋一下:

Clear
#Define ERROR_INSUFFICIENT_BUFFER 122
Declare Integer GetIfTable In iphlpapi String @pIfTable,Long @pdwSize,Long Border
Declare String inet_ntoa In wsock32 Long inn
m.pIfTable=''
m.pdwSize=0
m.iResult=GetIfTable(@m.pIfTable,@m.pdwSize,1)
If (m.iResult<>ERROR_INSUFFICIENT_BUFFER)
    ?'错误,Windows 错误代码:',m.iResult
    Return
Endif
m.pIfTable=Replicate(Chr(0),m.pdwSize)
m.iResult=GetIfTable(@m.pIfTable,@m.pdwSize,1)
If (m.iResult<>0)
    ?'错误,Windows 错误代码:',m.iResult
    Return
Endif
m.iCount=CToBin(Left(m.pIfTable,4),'rs')    &&网络连接总数
m.pIfTable=Substr(m.pIfTable,5)
For I=1 To m.iCount
    m.cMIB_IFROW=Substr(m.pIfTable,1+(I-1)*512,512)
    m.iIndex=CToBin(Substr(m.cMIB_IFROW,1,4),'rs')
    If m.iIndex>0
        m.iType=MyGetType(CToBin(Substr(m.cMIB_IFROW,5,4),'rs'))
        m.iMtu=CToBin(Substr(m.cMIB_IFROW,9,4),'rs')
        m.iSpeed=CToBin(Substr(m.cMIB_IFROW,13,4),'rs')
        m.iPhysAddrLen=CToBin(Substr(m.cMIB_IFROW,17,4),'rs')
        m.iPhysAddr=Substr(m.cMIB_IFROW,21,8)
        m.iAdminStatus=CToBin(Substr(m.cMIB_IFROW,29,4),'rs')
        (CToBin(Substr(m.cMIB_IFROW,33,4),'rs'))
        m.iLastChange=CToBin(Substr(m.cMIB_IFROW,37,4),'rs')
        m.iInOctets=CToBin(Substr(m.cMIB_IFROW,41,4),'rs')
        m.iInUcastPkts=CToBin(Substr(m.cMIB_IFROW,45,4),'rs')
        m.iInNUcastPkts=CToBin(Substr(m.cMIB_IFROW,49,4),'rs')
        m.iInDiscards=CToBin(Substr(m.cMIB_IFROW,53,4),'rs')
        m.iInErrors=CToBin(Substr(m.cMIB_IFROW,57,4),'rs')
        m.iInUnknownProtos=CToBin(Substr(m.cMIB_IFROW,61,4),'rs')
        (Substr(m.cMIB_IFROW,65,4),'rs')
        (Substr(m.cMIB_IFROW,69,4),'rs')
        (Substr(m.cMIB_IFROW,73,4),'rs')
        (Substr(m.cMIB_IFROW,77,4),'rs')
        (Substr(m.cMIB_IFROW,81,4),'rs')
        (Substr(m.cMIB_IFROW,85,4),'rs')
        m.iDescrLen=CToBin(Substr(m.cMIB_IFROW,89,4),'rs')
        m.iDescr=Substr(m.cMIB_IFROW,93,256)
        ?'m.iIndex',m.iIndex    &&接口编号
        ?'m.iType',m.iType        &&接口类型
        ?'m.iMtu',m.iMtu        &&最大传输单元
        ?'m.iSpeed',m.iSpeed    &&接口速度(字节)
        ?'m.iPhysAddrLen',m.iPhysAddrLen    &&由bPhysAddr获得的物理地址有效长度
        ?'m.iPhysAddr',m.iPhysAddr            &&物理地址
        ?'m.iAdminStatus',m.iAdminStatus    &&接口管理状态
        ?'',        &&操作状态
        ?'m.iLastChange',m.iLastChange        &&操作状态最后改变的时间
        ?'m.iInOctets',m.iInOctets            &&总共收到(字节)
        ?'m.iInUcastPkts',m.iInUcastPkts    &&总共收到(unicast包)
        ?'m.iInNUcastPkts',m.iInNUcastPkts    &&总共收到(non-unicast包),包括广播包和多点传送包
        ?'m.iInDiscards',m.iInDiscards        &&收到后丢弃包总数(即使没有错误)
        ?'m.iInErrors',m.iInErrors            &&收到出错包总数
        ?'m.iInUnknownProtos',m.iInUnknownProtos    &&收到后因协议不明而丢弃的包总数
        ?'',                &&总共发送(字节)
        ?'',            &&总共发送(unicast包)
        ?'',        &&总共发送(non-unicast包),包括广播包和多点传送包
        ?'',            &&发送丢弃包总数(即使没有错误)
        ?'',                &&发送出错包总数
        ?'',                    &&发送队列长度
        ?'m.iDescrLen',m.iDescrLen                    &&bDescr部分有效长度
        ?'m.iDescr',m.iDescr                        &&接口描述
    Endif
Endfor
Clear Dlls

Function MyGetType     &&“接口类型”定义函数
    Parameters tnType
    Do Case
        Case tnType=1
            lcType="Other"
        Case tnType=6
            lcType="Ethernet"
        Case tnType=9
            lcType="Tokenring"
        Case tnType=15
            lcType="FDDI"
        Case tnType=23
            lcType="PPP"
        Case tnType=24
            lcType="Loopback"
        Case tnType=28
            lcType="Loopback"
        Otherwise
            lcType="UNKNOW"
    Endcase
    Return lcType
Endfunc

Function MyGetState        &&“操作状态”定义函数
    Parameters tnState
    Do Case
        Case tnState=0
            lcState="Not operational"
        Case tnState=1
            lcState="Operational"
        Case tnState=2
            lcState="Disconnected"
        Case tnState=3
            lcState="Connecting"
        Case tnState=4
            lcState="Connected"
        Case tnState=5
            lcState="Unreachable"
        Otherwise
            lcState="UNKNOW"
    Endcase
    Return lcState
2008-03-21 19:12
快速回复:请大侠们帮忙写出这段代码!!(已解决)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017433 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved