Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- **************************************************************************
- * Project: raIP-Finder *
- * Purpose: GUI for getting IP of a given URL *
- * File: raip.c *
- * Version: 1.0 RELEASE *
- * Author: Michael Bergmann *
- * Date: 2026/02/01 *
- * Tested Compilers: amiga-gcc v6.5 *
- * m68k-amigaos-gcc -Wall -s -Os raip.c -o raIP -lamiga -lsocket -noixemul *
- **************************************************************************
- */
- #include <clib/macros.h>
- #include <clib/alib_protos.h>
- #include <clib/compiler-specific.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <proto/utility.h>
- #include <proto/graphics.h>
- #include <proto/intuition.h>
- #include <proto/gadtools.h>
- #include <proto/icon.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
- #include <netdb.h>
- #include <sys/types.h>
- /* network includes */
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <bsdsocket/socketbasetags.h>
- #include <proto/window.h>
- #include <proto/layout.h>
- #include <proto/button.h>
- #include <proto/string.h>
- #include <proto/label.h>
- #include <proto/requester.h>
- #include <classes/requester.h>
- #include <libraries/gadtools.h>
- #include <reaction/reaction.h>
- #include <intuition/gadgetclass.h>
- #include <intuition/icclass.h>
- #include <reaction/reaction_macros.h>
- #include <classes/window.h>
- #include <exec/memory.h>
- #define mydebug FALSE /* Debugging Texts TRUE or FALSE */
- /* --- Version String ------------------ */
- const UBYTE VersionTag[] = "\0$VER: IP-Finder v1.0 (02.01.2026) (c) Micha B.\0";
- /* --- Other global variables ---------- */
- char *url_string;
- char *ip_string;
- /* --- Function Prototypes ------------- */
- void window_main( void );
- int setup( void );
- void cleanup( void );
- void runWindow(
- Object *window_object, int window_id,
- struct Menu *menu_strip, struct Gadget *win_gadgets[]
- );
- int req_about(Object *reactionWindow);
- int req_quit(Object *reactionWindow);
- /* --- Screen Info ----------------------*/
- struct Screen *gScreen = NULL;
- struct DrawInfo *gDrawInfo = NULL;
- APTR gVisinfo = NULL;
- struct MsgPort *gAppPort = NULL;
- /* --- Menu IDs -------------------------------------------------------------- */
- enum menus
- {
- /* Menu "Projekt" */
- MN_CLEAR, MN_GETIP, MN_ABOUT, MN_QUIT
- };
- /* --- EasyRequesters -------------------------------------------------------- */
- struct EasyStruct warnreq =
- {
- sizeof(struct EasyStruct),
- 0,
- "Error",
- "raIP-Finder needs AmigaOS 3.2.x\n\nNo Chance to run this program on your machine!",
- "Ok"
- };
- /* --- ReAction Requester: req_about() --------------------------------------- */
- int req_about(Object *reactionWindow)
- {
- Object *reqobj;
- ULONG win;
- int res=0;
- GetAttr(WINDOW_Window, reactionWindow, &win);
- reqobj = NewObject(REQUESTER_GetClass(), NULL, REQ_Type, REQTYPE_INFO, REQ_Image, REQIMAGE_INFO,
- REQ_TitleText, "About IP-Finder",
- REQ_BodyText,"raIP-Finder v1.0 \nThis program shows the IP of a given URL \n\n" \
- "based on a MUI program by [email protected]\n\n " \
- "Author: Micha B. 2026/01 \n Web: www.mbergmann-sh.de \n Email: [email protected] \n\n" \
- "GUI made with ReBuild v1.3 beta\n" \
- "ReBuild is © by Darren Coles\n\n" \
- "Compiler: Bebbo's amiga-gcc v6.5.0b 251015095727 ",
- REQ_GadgetText, "_Ok",
- TAG_DONE);
- if (reqobj)
- {
- res=DoMethod(reqobj, RM_OPENREQ, NULL, win, NULL);
- DisposeObject(reqobj);
- }
- return res;
- } /* END req_about() */
- /* --- ReAction Requester: req_quit() ------------------------------------------ */
- int req_quit(Object *reactionWindow)
- {
- Object *reqobj;
- ULONG win;
- int res=0;
- GetAttr(WINDOW_Window, reactionWindow, &win);
- reqobj = NewObject(REQUESTER_GetClass(), NULL, REQ_Type, REQTYPE_INFO, REQ_Image, REQIMAGE_QUESTION,
- REQ_TitleText, "IP-Finder says 'Good bye!'",
- REQ_BodyText," You are about to quit this program.\n Do you really want to do that, dude? ",
- REQ_GadgetText, "_Yes, quit now!|_Cancel",
- TAG_DONE);
- if (reqobj)
- {
- res=DoMethod(reqobj, RM_OPENREQ, NULL, win, NULL);
- DisposeObject(reqobj);
- }
- return res;
- } /* END reqquit*/
- struct Library *WindowBase = NULL,
- *ButtonBase = NULL,
- *StringBase = NULL,
- *LabelBase = NULL,
- *RequesterBase = NULL,
- *GadToolsBase = NULL,
- *LayoutBase = NULL,
- *IconBase = NULL;
- struct IntuitionBase *IntuitionBase = NULL;
- //window ids
- enum win { window_main_id = 4 };
- //Window_Main gadgets
- enum window_main_idx { vert_mainlayout, horiz_parameter, vert_http, string_http, string_address,
- horiz_controls, button_clear, button_getip };
- enum window_main_id { vert_mainlayout_id = 6, horiz_parameter_id = 7, vert_http_id = 8,
- string_http_id = 10, string_address_id = 11, horiz_controls_id = 12,
- button_clear_id = 13, button_getip_id = 14 };
- /* --- Function: setup() --------------------------------------------------------------------------------- */
- /* --- Open libs, gadgets, classes and other ressources -------------------------------------------------- */
- int setup( void )
- {
- if( !(IntuitionBase = (struct IntuitionBase*) OpenLibrary("intuition.library",0L)) ) return 0;
- if( !(GadToolsBase = (struct Library*) OpenLibrary("gadtools.library",0L) ) ) return 0;
- if( !(WindowBase = (struct Library*) OpenLibrary("window.class",0L) ) ) return 0;
- if( !(IconBase = (struct Library*) OpenLibrary("icon.library",0L) ) ) return 0;
- /* --- Check for a sufficient OS! --- */
- if( !(LayoutBase = (struct Library*) OpenLibrary("gadgets/layout.gadget",47L) ) )
- {
- EasyRequest(NULL, &warnreq, NULL);
- return 0;
- }
- if( !(ButtonBase = (struct Library*) OpenLibrary("gadgets/button.gadget",0L) ) ) return 0;
- if( !(StringBase = (struct Library*) OpenLibrary("gadgets/string.gadget",0L) ) ) return 0;
- if( !(LabelBase = (struct Library*) OpenLibrary("images/label.image",0L) ) ) return 0;
- if( !(RequesterBase = (struct Library*) OpenLibrary("classes/requester.class",0L) ) )
- {
- puts("ERROR: Could not open requester.class.\n");
- return 0;
- }
- if( !(gScreen = LockPubScreen( 0 ) ) ) return 0;
- if( !(gVisinfo = GetVisualInfo( gScreen, TAG_DONE ) ) ) return 0;
- if( !(gDrawInfo = GetScreenDrawInfo ( gScreen ) ) ) return 0;
- if( !(gAppPort = CreateMsgPort() ) ) return 0;
- return -1;
- } /* END setup() */
- /* --- Function: cleanup() -------------------------------------------------------------------------------- */
- /* --- Close used ressources and clean up for shutdown ---------------------------------------------------- */
- void cleanup( void )
- {
- if ( gDrawInfo ) FreeScreenDrawInfo( gScreen, gDrawInfo);
- if ( gVisinfo ) FreeVisualInfo( gVisinfo );
- if ( gAppPort ) DeleteMsgPort( gAppPort );
- if ( gScreen ) UnlockPubScreen( 0, gScreen );
- if (GadToolsBase) CloseLibrary( (struct Library *)GadToolsBase );
- if (IconBase) CloseLibrary( (struct Library *)IconBase );
- if (IntuitionBase) CloseLibrary( (struct Library *)IntuitionBase );
- if (ButtonBase) CloseLibrary( (struct Library *)ButtonBase );
- if (StringBase) CloseLibrary( (struct Library *)StringBase );
- if (LabelBase) CloseLibrary( (struct Library *)LabelBase );
- if (LayoutBase) CloseLibrary( (struct Library *)LayoutBase );
- if (WindowBase) CloseLibrary( (struct Library *)WindowBase );
- if (RequesterBase) CloseLibrary( (struct Library *)RequesterBase );
- } /* END cleanup() */
- /* --- Function: runWindow() -------------------------------------------------------------------------------- */
- /* --- Application's message handling is done here! --------------------------------------------------------- */
- void runWindow( Object *window_object, int window_id, struct Menu *menu_strip, struct Gadget *win_gadgets[] )
- {
- struct Window *main_window = NULL;
- struct MenuItem *menuitem = NULL;
- LONG myItem = 0;
- ULONG status = 0;
- int req_result = 0;
- struct hostent *h;
- if ( window_object )
- {
- if ( main_window = (struct Window *) RA_OpenWindow( window_object ))
- {
- WORD Code;
- ULONG wait = 0, signal = 0, result = 0, done = FALSE;
- GetAttr( WINDOW_SigMask, window_object, &signal );
- if ( menu_strip) SetMenuStrip( main_window, menu_strip );
- while ( !done)
- {
- wait = Wait( signal | SIGBREAKF_CTRL_C );
- if ( wait & SIGBREAKF_CTRL_C )
- done = TRUE;
- else
- while (( result = RA_HandleInput( window_object, &Code )) != WMHI_LASTMSG)
- {
- switch ( result & WMHI_CLASSMASK )
- {
- /* --- WMHI_CLOSEWINDOW --------------------------------------------- */
- case WMHI_CLOSEWINDOW:
- SetAttrs(window_object, WA_BusyPointer, TRUE, TAG_DONE); /* Modal: ON */
- /* call Quit-Requester */
- req_result = req_quit(window_object);
- if (req_result == 1) done = TRUE;
- SetAttrs(window_object, WA_BusyPointer, FALSE, TAG_DONE); /* Modal: OFF */
- break;
- /* --- Menus -------------------------------------------------------- */
- case WMHI_MENUPICK:
- menuitem = ItemAddress(menu_strip, result & WMHI_MENUMASK);
- if(mydebug)
- {
- puts("menu pick");
- printf("ItemAdress = %ld\n", menuitem);
- }
- /* Check if menuitem equals to Zero. If Zero, an enforcer hit will occour when */
- /* attempting to examine,so we do not allow switching on menuitem == 0! */
- if(!(menuitem == 0))
- {
- /* --- ...get menu entries by using GadTools' GTMENUITEM_USERDATA field macro --- */
- myItem = ((long)GTMENUITEM_USERDATA(ItemAddress(menu_strip, result & WMHI_MENUMASK)));
- /* --- Identify selected menu entry */
- /* MN_CLEAR, MN_GETIP, MN_ABOUT, MN_QUIT */
- switch(myItem)
- {
- /* --- Menu "Project" --- */
- case MN_CLEAR:
- if(mydebug)
- {
- puts("Clear");
- }
- /* empty URL string gadget */
- SetGadgetAttrs( (APTR)win_gadgets[string_http], main_window, NULL, STRINGA_TextVal, "", TAG_END );
- /* empty IP string gadget */
- SetGadgetAttrs( (APTR)win_gadgets[string_address], main_window, NULL, STRINGA_TextVal, "", TAG_END );
- break;
- case MN_GETIP:
- if(mydebug)
- {
- puts("Get IP");
- }
- /* Get URL string */
- GetAttr(STRINGA_TextVal, (APTR)win_gadgets[string_http], (ULONG *)&url_string);
- h = gethostbyname(url_string);
- /* Set IP string */
- SetGadgetAttrs((APTR)win_gadgets[string_address], main_window, NULL, STRINGA_TextVal, inet_ntoa(*((struct in_addr *)h->h_addr)), TAG_END);
- break;
- break;
- case MN_ABOUT:
- if(mydebug)
- {
- puts("About");
- }
- SetAttrs(window_object, WA_BusyPointer, TRUE, TAG_DONE); /* Modal: ON */
- req_result = req_about(window_object);
- SetAttrs(window_object, WA_BusyPointer, FALSE, TAG_DONE); /* Modal: OFF */
- break;
- case MN_QUIT:
- if(mydebug)
- {
- puts("Quit");
- }
- SetAttrs(window_object, WA_BusyPointer, TRUE, TAG_DONE); /* Modal: ON */
- /* call Quit-Requester */
- req_result = req_quit(window_object);
- if (req_result == 1) done = TRUE;
- SetAttrs(window_object, WA_BusyPointer, FALSE, TAG_DONE); /* Modal: OFF */
- break;
- } /* END switch(myitem) */
- } /* END Check menu items for zero*/
- break;
- /* --- Gadgets ----------------------------------------------------- */
- case WMHI_GADGETUP:
- switch (result & WMHI_GADGETMASK)
- {
- case button_clear_id:
- if(mydebug)
- {
- puts("Button: Clear");
- }
- /* empty URL string gadget */
- SetGadgetAttrs( (APTR)win_gadgets[string_http], main_window, NULL, STRINGA_TextVal, "", TAG_END );
- /* empty IP string gadget */
- SetGadgetAttrs( (APTR)win_gadgets[string_address], main_window, NULL, STRINGA_TextVal, "", TAG_END );
- break;
- case button_getip_id:
- if(mydebug)
- {
- puts("Button: Get IP");
- }
- /* Get URL string */
- GetAttr(STRINGA_TextVal, (APTR)win_gadgets[string_http], (ULONG *)&url_string);
- h = gethostbyname(url_string);
- /* Set IP string */
- SetGadgetAttrs((APTR)win_gadgets[string_address], main_window, NULL, STRINGA_TextVal, inet_ntoa(*((struct in_addr *)h->h_addr)), TAG_END);
- break;
- }
- break;
- /* --- Iconify ----------------------------------------------------- */
- case WMHI_ICONIFY:
- if ( RA_Iconify( window_object ) )
- main_window = NULL;
- break;
- /* --- Uniconify --------------------------------------------------- */
- case WMHI_UNICONIFY:
- main_window = RA_OpenWindow( window_object );
- if ( menu_strip) SetMenuStrip( main_window, menu_strip );
- break;
- } /* END switch(result & WMHI_CLASSMASK */
- } /* END while (( result = RA_HandleInput( window_object, &Code )) != WMHI_LASTMSG) */
- } /* END while(!done) */
- } /* END if ( main_window = (struct Window *) RA_OpenWindow( window_object )) */
- } /* END if(window_object) */
- } /* END runWindow() */
- /* --- Function: window_main() ---------------------------------------------------------------------------------------- */
- /* --- All window-specific setup for main Window is done here. runWindow() is called for message handling afterwards. - */
- void window_main( void )
- {
- struct NewMenu menuData[] =
- {
- { NM_TITLE, "Project", 0, 0, 0, NULL },
- { NM_ITEM, "Clear", "C", 0, 62, (APTR) MN_CLEAR },
- { NM_ITEM, "Get IP", "G", 0, 61, (APTR) MN_GETIP },
- { NM_ITEM, NM_BARLABEL, 0, 0, 59, NULL },
- { NM_ITEM, "About...", "A", 0, 55, (APTR) MN_ABOUT },
- { NM_ITEM, NM_BARLABEL, 0, 0, 47, NULL },
- { NM_ITEM, "Quit", "Q", 0, 31, (APTR) MN_QUIT },
- { NM_END, NULL, 0, 0, 0, (APTR)0 }
- };
- struct Menu *menu_strip = NULL;
- struct Gadget *main_gadgets[ 9 ];
- Object *window_object = NULL;
- struct HintInfo hintInfo[] =
- {
- {vert_mainlayout_id,-1,"",0},
- {horiz_parameter_id,-1,"",0},
- {vert_http_id,-1,"",0},
- {string_http_id,-1,"Enter URL to look up",0},
- {string_address_id,-1,"IP is shown here",0},
- {horiz_controls_id,-1,"",0},
- {button_clear_id,-1,"Clear Mask",0},
- {button_getip_id,-1,"Get a domain's IP",0},
- {-1,-1,NULL,0}
- };
- menu_strip = CreateMenusA( menuData, TAG_END );
- LayoutMenus( menu_strip, gVisinfo,
- GTMN_NewLookMenus, TRUE,
- TAG_DONE );
- window_object = NewObject( WINDOW_GetClass(), NULL,
- WA_Title, "raIP-Finder v1.0",
- WA_ScreenTitle, "raIP-Finder v1.0",
- WA_Left, 5,
- WA_Top, 20,
- WA_Width, 150,
- WA_Height, 20,
- WA_MinWidth, 150,
- WA_MinHeight, 20,
- WA_MaxWidth, 8192,
- WA_MaxHeight, 8192,
- WINDOW_LockHeight, TRUE,
- WINDOW_IconifyGadget, TRUE,
- WINDOW_HintInfo, hintInfo,
- WINDOW_GadgetHelp, TRUE,
- WINDOW_AppPort, gAppPort,
- WINDOW_IconifyGadget, TRUE,
- WA_CloseGadget, TRUE,
- WA_DepthGadget, TRUE,
- WA_SizeGadget, TRUE,
- WA_DragBar, TRUE,
- WA_Activate, TRUE,
- WA_SizeBBottom, TRUE,
- WINDOW_Position, WPOS_TOPLEFT,
- WINDOW_IconTitle, "raIP",
- WINDOW_Icon, GetDiskObject("raIP"),
- WA_NoCareRefresh, TRUE,
- WA_IDCMP, IDCMP_GADGETUP | IDCMP_CLOSEWINDOW | IDCMP_MENUPICK | IDCMP_NEWSIZE | IDCMP_IDCMPUPDATE,
- WINDOW_ParentGroup, NewObject( LAYOUT_GetClass(), NULL,
- LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
- LAYOUT_SpaceOuter, TRUE,
- LAYOUT_DeferLayout, TRUE,
- LAYOUT_AddChild, main_gadgets[vert_mainlayout] = NewObject( LAYOUT_GetClass(), NULL,
- GA_ID, vert_mainlayout_id,
- LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
- LAYOUT_SpaceOuter, TRUE,
- LAYOUT_LeftSpacing, 2,
- LAYOUT_RightSpacing, 2,
- LAYOUT_TopSpacing, 2,
- LAYOUT_BottomSpacing, 2,
- LAYOUT_DeferLayout, TRUE,
- LAYOUT_AddChild, main_gadgets[horiz_parameter] = NewObject( LAYOUT_GetClass(), NULL,
- GA_ID, horiz_parameter_id,
- LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
- LAYOUT_HorizAlignment, LALIGN_CENTER,
- LAYOUT_BevelStyle, BVS_THIN,
- LAYOUT_LeftSpacing, 2,
- LAYOUT_RightSpacing, 2,
- LAYOUT_TopSpacing, 2,
- LAYOUT_BottomSpacing, 2,
- LAYOUT_Label, "Get IP Address",
- LAYOUT_EvenSize, TRUE,
- LAYOUT_AddChild, main_gadgets[vert_http] = NewObject( LAYOUT_GetClass(), NULL,
- GA_ID, vert_http_id,
- LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
- LAYOUT_EvenSize, TRUE,
- LAYOUT_DeferLayout, TRUE,
- LAYOUT_AddChild, main_gadgets[string_http] = NewObject( STRING_GetClass(), NULL,
- GA_ID, string_http_id,
- GA_RelVerify, TRUE,
- GA_TabCycle, TRUE,
- STRINGA_TextVal, "google.com",
- STRINGA_MaxChars, 175,
- STRINGA_MinVisible, 15,
- TAG_END),
- CHILD_Label, NewObject( LABEL_GetClass(), NULL,
- LABEL_Text, "Enter URL - http://",
- TAG_END),
- LAYOUT_AddChild, main_gadgets[string_address] = NewObject( STRING_GetClass(), NULL,
- GA_ID, string_address_id,
- GA_RelVerify, TRUE,
- GA_TabCycle, TRUE,
- STRINGA_MaxChars, 80,
- TAG_END),
- CHILD_Label, NewObject( LABEL_GetClass(), NULL,
- LABEL_Text, "IP Address:",
- TAG_END),
- TAG_END),
- TAG_END),
- LAYOUT_AddChild, main_gadgets[horiz_controls] = NewObject( LAYOUT_GetClass(), NULL,
- GA_ID, horiz_controls_id,
- LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
- LAYOUT_BevelStyle, BVS_THIN,
- LAYOUT_LeftSpacing, 2,
- LAYOUT_RightSpacing, 2,
- LAYOUT_TopSpacing, 2,
- LAYOUT_BottomSpacing, 2,
- LAYOUT_Label, "Controls",
- LAYOUT_EvenSize, TRUE,
- LAYOUT_DeferLayout, TRUE,
- LAYOUT_AddChild, main_gadgets[button_clear] = NewObject( BUTTON_GetClass(), NULL,
- GA_ID, button_clear_id,
- GA_Text, "_Clear",
- GA_RelVerify, TRUE,
- GA_TabCycle, TRUE,
- BUTTON_TextPen, 1,
- BUTTON_BackgroundPen, 0,
- BUTTON_FillTextPen, 1,
- BUTTON_FillPen, 3,
- TAG_END),
- LAYOUT_AddChild, main_gadgets[button_getip] = NewObject( BUTTON_GetClass(), NULL,
- GA_ID, button_getip_id,
- GA_Text, "_Get IP",
- GA_RelVerify, TRUE,
- GA_TabCycle, TRUE,
- BUTTON_TextPen, 1,
- BUTTON_BackgroundPen, 0,
- BUTTON_FillTextPen, 1,
- BUTTON_FillPen, 3,
- TAG_END),
- TAG_END),
- TAG_END),
- TAG_END),
- TAG_END);
- main_gadgets[8] = 0;
- runWindow( window_object, window_main_id, menu_strip, main_gadgets );
- if ( window_object ) DisposeObject( window_object );
- if ( menu_strip ) FreeMenus( menu_strip );
- } /* END window_main() */
- /* --- Main Function ---------------------------------------------------------------------------------- */
- int main(void)
- {
- if ( setup() ) /* This will satisfy all needs... */
- {
- window_main(); /* ...and open Application's main Window by running 'runWindow()' */
- }
- cleanup(); /* Clean up stuff and exit */
- } /* END main() */
Advertisement
Add Comment
Please, Sign In to add comment