API Ping Command In Powerbuilder
Example Window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
forward global type w_main from window end type type st_status from statictext within w_main end type type st_1 from statictext within w_main end type type sle_ip from singlelineedit within w_main end type type cb_ping from commandbutton within w_main end type type str_wsadata from structure within w_main end type type str_inaddr from structure within w_main end type type str_ip_option_information from structure within w_main end type type str_icmp_echo_reply from structure within w_main end type end forward type str_wsadata from structure unsignedinteger version unsignedinteger highversion character description[257] character systemstatus[129] unsignedinteger maxsockets unsignedinteger maxupddg string vendorinfo end type type str_inaddr from structure unsignedlong s_addr end type type str_ip_option_information from structure character ttl character tos character flags character optionssize unsignedlong optionsdata end type type str_icmp_echo_reply from structure unsignedlong address unsignedlong status unsignedlong roundtriptime unsignedlong datasize unsignedinteger reserved unsignedlong ptrdata str_ip_option_information options character data[256] end type global type w_main from window integer width = 1573 integer height = 544 boolean titlebar = true string title = "Ping" boolean controlmenu = true boolean minbox = true boolean maxbox = true boolean resizable = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true st_status st_status st_1 st_1 sle_ip sle_ip cb_ping cb_ping end type global w_main w_main type prototypes //Open the socket connection. Function Integer WSAStartup( UInt UIVersionRequested, Ref str_WSAData lpWSAData ) Library "wsock32.dll" Alias For "WSAStartup;ANSI" //Clean up sockets. Function Integer WSACleanup() Library "wsock32.dll" Alias For "WSACleanup;ANSI" //Create a handle on which Internet Control Message Protocol (ICMP) requests can be issued. Function ULong IcmpCreateFile() Library "icmp.dll" //Close an Internet Control Message Protocol (ICMP) handle that IcmpCreateFile opens. Function ULong IcmpCloseHandle(ULong IcmpHandle) Library "icmp.dll" //Send an Internet Control Message Protocol (ICMP) echo request, and then return one or more replies. Function ULong IcmpSendEcho(ULong IcmpHandle,ULong DestinationAddress,String RequestData,ULong RequestSize,ULong RequestOptions,Ref str_icmp_echo_reply ReplyBuffer,ULong ReplySize,ULong TimeOut) Library "icmp.dll" Alias For "IcmpSendEcho;ANSI" // Convert a string that contains an (Ipv4) Internet Protocol dotted address into a correct address. Function ULong inet_addr(String ip_addr) Library "ws2_32.dll" Alias For "inet_addr;ANSI" end prototypes type variables Constant ULong WS_VERSION_REQD = 257 Constant Long ICMP_SUCCESS = 0 Constant Long ICMP_STATUS_BUFFER_TO_SMALL = 11001 //Buffer Too Small Constant Long ICMP_STATUS_DESTINATION_NET_UNREACH = 11002 //Destination Net Unreachable Constant Long ICMP_STATUS_DESTINATION_HOST_UNREACH = 11003 //Destination Host Unreachable Constant Long ICMP_STATUS_DESTINATION_PROTOCOL_UNREACH = 11004 //Destination Protocol Unreachable Constant Long ICMP_STATUS_DESTINATION_PORT_UNREACH = 11005 //Destination Port Unreachable Constant Long ICMP_STATUS_NO_RESOURCE = 11006 //No Resources Constant Long ICMP_STATUS_BAD_OPTION = 11007 //Bad Option Constant Long ICMP_STATUS_HARDWARE_ERROR = 11008 //Hardware Error Constant Long ICMP_STATUS_LARGE_PACKET = 11009 //Packet Too Big Constant Long ICMP_STATUS_REQUEST_TIMED_OUT = 11010 //Request Timed Out Constant Long ICMP_STATUS_BAD_REQUEST = 11011 //Bad Request Constant Long ICMP_STATUS_BAD_ROUTE = 11012 //Bad Route Constant Long ICMP_STATUS_TTL_EXPIRED_TRANSIT = 11013 //TimeToLive Expired Transit Constant Long ICMP_STATUS_TTL_EXPIRED_REASSEMBLY = 11014 //TimeToLive Expired Reassembly Constant Long ICMP_STATUS_PARAMETER = 11015 //Parameter Problem Constant Long ICMP_STATUS_SOURCE_QUENCH = 11016 //Source Quench Constant Long ICMP_STATUS_OPTION_TOO_BIG = 11017 //Option Too Big Constant Long ICMP_STATUS_BAD_DESTINATION = 11018 //Bad Destination Constant Long ICMP_STATUS_NEGOTIATING_IPSEC = 11032 //Negotiating IPSEC Constant Long ICMP_STATUS_GENERAL_FAILURE = 11050 //General Failure end variables forward prototypes public function string wf_icmpmsg (unsignedlong pingresponse) end prototypes public function string wf_icmpmsg (unsignedlong pingresponse);String ls_ret Choose Case PingResponse Case ICMP_SUCCESS ls_ret = "Success!" Case ICMP_STATUS_BUFFER_TO_SMALL ls_ret = "Buffer Too Small" Case ICMP_STATUS_DESTINATION_NET_UNREACH ls_ret = "Destination Net Unreachable" Case ICMP_STATUS_DESTINATION_HOST_UNREACH ls_ret = "Destination Host Unreachable" Case ICMP_STATUS_DESTINATION_PROTOCOL_UNREACH ls_ret = "Destination Protocol Unreachable" Case ICMP_STATUS_DESTINATION_PORT_UNREACH ls_ret = "Destination Port Unreachable" Case ICMP_STATUS_NO_RESOURCE ls_ret = "No Resources" Case ICMP_STATUS_BAD_OPTION ls_ret = "Bad Option" Case ICMP_STATUS_HARDWARE_ERROR ls_ret = "Hardware Error" Case ICMP_STATUS_LARGE_PACKET ls_ret = "Packet Too Big" Case ICMP_STATUS_REQUEST_TIMED_OUT ls_ret = "Request Timed Out" Case ICMP_STATUS_BAD_REQUEST ls_ret = "Bad Request" Case ICMP_STATUS_BAD_ROUTE ls_ret = "Bad Route" Case ICMP_STATUS_TTL_EXPIRED_TRANSIT ls_ret = "TimeToLive Expired Transit" Case ICMP_STATUS_TTL_EXPIRED_REASSEMBLY ls_ret = "TimeToLive Expired Reassembly" Case ICMP_STATUS_PARAMETER ls_ret = "Parameter Problem" Case ICMP_STATUS_SOURCE_QUENCH ls_ret = "Source Quench" Case ICMP_STATUS_OPTION_TOO_BIG ls_ret = "Option Too Big" Case ICMP_STATUS_BAD_DESTINATION ls_ret = "Bad Destination" Case ICMP_STATUS_NEGOTIATING_IPSEC ls_ret = "Negotiating IPSEC" Case ICMP_STATUS_GENERAL_FAILURE ls_ret = "General Failure" Case Else ls_ret = "Unknown Response" End Choose Return ls_ret end function on w_main.create this.st_status=create st_status this.st_1=create st_1 this.sle_ip=create sle_ip this.cb_ping=create cb_ping this.Control[]={this.st_status,& this.st_1,& this.sle_ip,& this.cb_ping} end on on w_main.destroy destroy(this.st_status) destroy(this.st_1) destroy(this.sle_ip) destroy(this.cb_ping) end on type st_status from statictext within w_main integer x = 402 integer y = 192 integer width = 1097 integer height = 224 integer textsize = -9 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "Status" boolean focusrectangle = false end type type st_1 from statictext within w_main integer y = 64 integer width = 366 integer height = 64 integer textsize = -9 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "IP Address:" alignment alignment = right! boolean focusrectangle = false end type type sle_ip from singlelineedit within w_main integer x = 402 integer y = 52 integer width = 1097 integer height = 96 integer taborder = 10 integer textsize = -9 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 borderstyle borderstyle = stylelowered! end type type cb_ping from commandbutton within w_main integer x = 110 integer y = 168 integer width = 256 integer height = 112 integer taborder = 10 integer textsize = -9 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Ping" end type event clicked;str_wsadata lstr_wsadata str_icmp_echo_reply lstr_reply ULong lul_timeout, lul_address, lul_hIcmp, lul_size Integer li_res String ls_pingIP, ls_send, ls_msg nvo_sizeof ln_size ls_pingIP = sle_ip.Text // "192.168.1.1" ls_send = "hello" lul_timeout = 1000 //(ms, 1 second) lstr_wsadata.vendorinfo = Space(256) //Establish SOCKET li_res = wsastartup (WS_VERSION_REQD, lstr_wsadata) If li_res <> 0 Then Return //Convert IP address string lul_address = inet_addr(ls_pingIP) If lul_address <> -1 And lul_address <> 0 Then //Create ICMP request lul_hIcmp = IcmpCreateFile() If IsNull(lul_hIcmp) Then //MessageBox("error","ICMP request establishment failed!") st_status.text = "ICMP request establishment failed!" Else lul_size = ln_size.sizeof(lstr_reply) IcmpSendEcho(lul_hIcmp, lul_address, ls_send, Len(ls_send), 0, lstr_reply,lul_size,lul_timeout) //Get information ls_msg = wf_icmpmsg(lstr_reply.status) st_status.text = "Icmp code: "+ String(lstr_reply.status) + "~r~n" + & "Response Message: "+ ls_msg + "~r~n" + & "Time: "+ String(lstr_reply.RoundTripTime) +" ms" //Close ICMP request IcmpCloseHandle(lul_hIcmp) End If Else MessageBox("error","IP address is illegal!") End If //Close SOCKET wsacleanup() end event |
nvo_sizeof from nonvisualobject
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
forward global type nvo_sizeof from nonvisualobject end type end forward global type nvo_sizeof from nonvisualobject autoinstantiate end type type variables Private: CONSTANT integer SIZE_BOOLEAN = 1 // Boolean CONSTANT integer SIZE_CHAR = 1 // Char CONSTANT integer SIZE_INT = 2 // Signed integer CONSTANT integer SIZE_UINT = 2 // Unsigned integer CONSTANT integer SIZE_LONG = 4 // Signed Long CONSTANT integer SIZE_ULONG = 4 // Unsigned Long CONSTANT integer SIZE_STRING = 4 // Assume as string pointer // Supported DataTypes integer INTEGER uint UINT long LONG ulong ULONG char CHAR string STRING boolean BOOLEAN end variables forward prototypes public function long sizeof (long data) public function long sizeof (unsignedlong data) public function long sizeof (integer data) public function long sizeof (unsignedinteger data) public function long sizeof (character data) public function long sizeof (string data) public function long sizeof (boolean data) public function long sizeof (any data[]) public function long sizeof (variabledefinition vardef[]) public function long sizeof (powerobject data) end prototypes public function long sizeof (long data);Return(SIZE_LONG) end function public function long sizeof (unsignedlong data);Return(SIZE_ULONG) end function public function long sizeof (integer data);Return(SIZE_INT) end function public function long sizeof (unsignedinteger data);Return(SIZE_UINT) end function public function long sizeof (character data);Return(SIZE_CHAR) end function public function long sizeof (string data);Return(SIZE_STRING) end function public function long sizeof (boolean data);Return(SIZE_BOOLEAN) end function public function long sizeof (any data[]);// Gives the dimension of an array // Arguments: Data[] => Array to know the dimension // Returns: Size of the array // Notes: // 1) Supports mixed type arrays (and variable sized strings within the array) // 2) DOESN 'T support multi-dimension arrays; Long ll_Index, ll_Count, ll_Size = 0 ll_Count = UpperBound(Data) For ll_Index = 1 To ll_Count Choose Case ClassName(Data[ll_Index]) Case "long" ll_Size += SizeOf(Long) Case "unsignedlong", "ulong" ll_Size += SizeOf(ULong) Case "int", "integer" ll_Size += SizeOf(Integer) Case "uint", "unsignedinteger", "unsignedint" ll_Size += SizeOf(UInt) Case "char", "character" ll_Size += SizeOf(Char) Case "string" ll_Size += SizeOf(Char) * SizeOf(String(Data[ll_Index])) Case "boolean" ll_Size += SizeOf(Boolean) End Choose Next Return(ll_Size) end function public function long sizeof (variabledefinition vardef[]);// Internal calculations for structure sizes Long ll_Index, ll_Count, ll_Size, ll_Array = 0 ClassDefinition TypeInfo VariableDefinition VarList[] VariableCardinalityDefinition VarCarDef ArrayBounds ArrBounds[] String ls_typeof ll_Count = UpperBound(VarDef) For ll_Index = 2 To ll_Count //ll_Index=1 itself VarCarDef = VarDef[ll_Index].Cardinality If VarCarDef.Cardinality = BoundedArray! Then ArrBounds = VarCarDef.ArrayDefinition If UpperBound(ArrBounds) = 1 Then ll_Array = ArrBounds[1].UpperBound ElseIf UpperBound(ArrBounds) >= 2 Then //two dim array ll_Array = (ArrBounds[2].UpperBound)*(ArrBounds[1].UpperBound) End If Else //ScalarType! or UnboundedArray! ll_Array = 1 End If ls_typeof = Lower(VarDef[ll_Index].TypeInfo.DataTypeOf) Choose Case ls_typeof Case "long" ll_Size += SizeOf(Long) * ll_Array Case "ulong", "unsignedlong" ll_Size += SizeOf(ULong) * ll_Array Case "int", "integer" ll_Size += SizeOf(Integer) * ll_Array Case "uint", "unsignedint", "unsignedinteger" ll_Size += SizeOf(UInt) * ll_Array Case "char", "character" ll_Size += SizeOf(Char) * ll_Array Case "string" ll_Size += SizeOf(String) * ll_Array Case "structure" TypeInfo = VarDef[ll_Index].TypeInfo VarList = TypeInfo.VariableList ll_Size += SizeOf(VarList) Case Else //if just store pointer in pb?? ll_Size+=(4*ll_Array) MessageBox( "SizeOf error ", "Type is not supported, possibly variable sized or object type! ",StopSign!,Ok!) Return (-1) End Choose Next Return(ll_Size) end function public function long sizeof (powerobject data);// This function calculates the size of a structure // The structure can contain simple datatypes (long, integer, boolean), arrays or // other structures within it // Arguments: Data => Structure to know the size of.. // Returns: Size of the structure or -1 if error // Notes: // 1) Cannot calculate the size of a structure with strings (variable size), for fixed // sized strings use a char array; // 2) CAN calculate the size of multi-dimension arrays within the structures ClassDefinition ClassDef VariableDefinition VarDef[] ClassDef = Data.ClassDefinition If Not ClassDef.IsStructure Then Return - 1 VarDef = ClassDef.VariableList Return(SizeOf(VarDef)) end function on nvo_sizeof.create call super::create TriggerEvent( this, "constructor" ) end on on nvo_sizeof.destroy TriggerEvent( this, "destructor" ) call super::destroy end on |
Find Projects On Github click here
Good Luck!
Please post the code for nvo_sizeof!!!
you can find it at projects github. I will update it back to the homepage. thank you