Using Win32 functions in Visual FoxPro Image Gallery
Windows Sockets 2 (Winsock)
..msdn
accept
bind
closesocket
gethostbyaddr
gethostbyname
gethostname
getnameinfo
getprotobyname
getprotobynumber
getservbyname
getservbyport
getsockopt
htonl
htons
inet_addr
inet_ntoa
listen
ntohl
ntohs
recv
recvfrom
send
sendto
setsockopt
socket
WSACleanup
WSACloseEvent
WSAConnect
WSACreateEvent
WSAEnumProtocols
WSAEventSelect
WSAGetLastError
WSARecv
WSASend
WSAStartup
WSAWaitForMultipleEvents
ws_connect
ws_select
Code examples:
Winsock: how to retrieve the protocol information corresponding to a protocol name
Winsock: how to retrieve the protocol information corresponding to a protocol name

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
 
DO decl
 
IF InitWinsock()
    = DisplayProtInfo ("tcp")
    = DisplayProtInfo ("udp")
    = WSACleanup()
ENDIF
* End of Main
 
PROCEDURE  DisplayProtInfo (lcProtName)
    LOCAL lnProtoentPtr
    lnProtoentPtr = getprotobyname(lcProtName)
 
    IF lnProtoentPtr = 0
    * no protocol found with this name
        ? lcProtName
        RETURN
    ENDIF
 
*| struct protoent {
*|   char FAR *        p_name;     0:4
*|   char FAR * FAR *  p_aliases;  4:4
*|   short             p_proto;    8:4
*| }; total bytes = 12
#DEFINE PROTOENT_SIZE  12
 
    LOCAL lcBuffer, lcProt, lcAliases, lnProt
    lcBuffer = Repli(Chr(0), PROTOENT_SIZE)
    = Heap2Str (@lcBuffer, lnProtoentPtr, PROTOENT_SIZE)
 
    lcProt    = GetMemStr(buf2dword(SUBSTR(lcBuffer, 1,4)))
    lcAliases = GetAliases(buf2dword(SUBSTR(lcBuffer, 5,4)))
    lnProt    = buf2word(SUBSTR(lcBuffer, 9,2))
 
    ? PADR(lcProt,20), STR(lnProt,5), lcAliases
RETURN
 
FUNCTION  GetAliases (lnArrayPtr)
* returns a string with alternate names for the protocol
* delimited with semicolons
    IF lnArrayPtr = 0
        EXIT
    ENDIF
 
    LOCAL lcResult, lnDataPtr, lcAlias
    lcResult = ""
 
    DO WHILE .T.
        * each array element contains a pointer to data
        lnDataPtr = buf2dword(GetMemBuf(lnArrayPtr, 4))
 
        IF lnDataPtr <> 0
            lcAlias = GetMemStr(lnDataPtr)
            lcResult = lcResult +;
                Iif(Empty(lcResult), "",";") + lcAlias
        ELSE
        * the last array element contains null
            EXIT
        ENDIF
        lnArrayPtr = lnArrayPtr + 4  && next array element
    ENDDO
RETURN  lcResult
 
FUNCTION  InitWinsock()
* Initializing the Winsock service for the application
#DEFINE WSADATA_SIZE 398
#DEFINE WS_VERSION 0x0202
    LOCAL lcWSADATA, lnInitResult
    lcWSADATA = Repli(Chr(0), WSADATA_SIZE)
    lnInitResult = WSAStartup (WS_VERSION, @lcWSADATA)
RETURN  (lnInitResult = 0)
 
FUNCTION  GetMemBuf (lnAddr, lnBufsize)
    LOCAL lcBuffer
    lcBuffer = Repli(Chr(0), lnBufsize)
    = Heap2Str (@lcBuffer, lnAddr, lnBufsize)
RETURN  lcBuffer
 
FUNCTION  GetMemStr (lnAddr)
* returning data from a memory block
* before the first occurence of a zero byte
    LOCAL lcBuffer
    lcBuffer = GetMemBuf (lnAddr, 250)
RETURN  SUBSTR(lcBuffer, 1, AT(Chr(0),lcBuffer)-1)
 
FUNCTION  buf2word (lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
    Asc(SUBSTR(lcBuffer, 2,1)) * 256
 
FUNCTION  buf2dword (lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
    Asc(SUBSTR(lcBuffer, 2,1)) * 256 +;
    Asc(SUBSTR(lcBuffer, 3,1)) * 65536 +;
    Asc(SUBSTR(lcBuffer, 4,1)) * 16777216
 
PROCEDURE  decl
    DECLARE INTEGER WSAStartup IN ws2_32 INTEGER wVerRq, STRING @lpWSAData
    DECLARE INTEGER WSACleanup IN ws2_32
    DECLARE INTEGER getprotobyname IN ws2_32 STRING name  
 
    DECLARE RtlMoveMemory IN kernel32 As Heap2Str;
        STRING @Dest, INTEGER Src, INTEGER nLength
 
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
2755 bytes  
Created: 2001-12-20 07:20:26  
Modified: 2005-12-27 10:44:42  
Visits in 7 days: 91  
Listed functions:
getprotobyname
WSACleanup
WSAStartup
Printer friendly API declarations
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.


Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

Privacy policy
Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (67.202.9.192)
3 sec.Function: 'CeGlobalMemoryStatus'
Function group: 'Remote Application Programming (RAPI)'
1.14 hrs.Example: 'Retrieving Printer Device Context using PrintDlg function'
 Function: 'GdipBitmapSetPixel'
 Function: 'RegCreateKeyEx'
3.02 hrs.Example: 'Reading the state of mouse buttons within DO WHILE loop'
4.77 hrs.Example: 'Using custom Simple MapiSendMail class'
 Example: 'How to set Creation Date/Time for a folder (WinNT)'
7.74 hrs.Function: 'RegDeleteValue'
Function group: 'Registry'
 Example: 'Winsock: changing the byte ordering'
8.07 hrs.Example: 'How to view icons stored in executable files (Icon Viewer) - II'
Google
Advertise here!